For the More Curious: The __block Modifier, Abbreviated Syntax, and Memory
Blocks have a few more options than we’ve talked about in this chapter. First, when allocating blocks we have always put the return type in the block signature:
^returnType(...) { }
However, this isn’t necessary. The compiler can figure out the return type based on the return statement in the block.
For example, these are all valid blocks and assignments:
int (^block)(void) = ^(void) { return 10; }; NSString * (^block)(void) = ^(void) { return [NSString stringWithString:@"Hey"]; }; void (^block)(void) ...
Get iOS 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.