Skip to content

Instantly share code, notes, and snippets.

@wenghengcong
Created May 7, 2019 13:07
Show Gist options
  • Select an option

  • Save wenghengcong/7941449f03135c4d7f48db336725c2f5 to your computer and use it in GitHub Desktop.

Select an option

Save wenghengcong/7941449f03135c4d7f48db336725c2f5 to your computer and use it in GitHub Desktop.
Block #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 parameter to a C function:
void SomeFunctionThatTakesABlock(returnType (^blockName)(parameterTypes));
As a typedef:
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment