Return Values
Blocks can also return values. The return type of the block can be specified after the caret, but if you omit it, the compiler will try to infer as much information about the return value as it can, allowing you to write more succinct code. This is a fully qualified block literal for NSArray’s -indexesOfObjectsPassingTest: method:
^BOOL (id object, NSUInteger index, BOOL *stop) { return YES; }
But you can reduce it a bit because the return type will be inferred:
^(id object, NSUInteger index, BOOL *stop) { return YES; }
A block that takes no arguments and returns no value can be drastically reduced:
^void ...
Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.