August 2011
Intermediate to advanced
552 pages
23h 48m
English
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 ...
Read now
Unlock full access