Objective-C Blocks

Enjoy this cheat sheet at its fullest within Dash, the macOS documentation browser.

Block Syntax

Block as a local variable

returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

Block as a property

@property (nonatomic, copy) returnType (^blockName)(parameterTypes);

Block as a method parameter

- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;

Block as an argument to a method call

[someObject someMethodThatTakesABlock: ^returnType (parameters) {...}];

Block as typedef

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};