2019-06-28

How Do I Declare A Block in Objective-C?

As alocal variable:


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

As aproperty:


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

As amethod parameter:


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

As anargument to a method call:


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

As aparameter to a C function:

void SomeFunctionThatTakesABlock(returnType (^blockName)(parameterTypes));

As atypedef:

typedef returnType (^TypeName)(parameterTypes);

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

转载来自http://fuckingblocksyntax.com/

你可能感兴趣的:(2019-06-28)