本文翻譯自http://fuckingblocksyntax.com/
作為區域性變數:
returnType(^blockName)(parameterTypes) = ^returnType(parameters) {...};
複製程式碼
作為屬性:
@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
複製程式碼
作為引數:
- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;
複製程式碼
作為方法呼叫引數:
[someObject someMethodThatTakesABlock:^returnType (parameters) {...} ];
複製程式碼
作為typedef
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
複製程式碼