How does I Declare A Block in objective-c? As a
local variable:
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
As a
Property:
@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
As a
method Parameter:
- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;
As an
argument to a method call:
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
As a
typedef:
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
This site is a exhaustive list of all possible uses of blocks for intended.
If you find yourself needing syntax isn't listed here, it's likely that a
typedefWould make your code more readable.
Unable to access this site due to the profanity in the URL?
http://goshdarnblocksyntax.comis a more work-friendly mirror.
By Mike Lazer-walker, who had a very bad memory for this sort of thing.
How does I Declare A Block in objective-c?