局部变量
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
举例:
int (^completion)(int a) = ^int(int a){
// ...
};
属性
@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
举例:
@property (nonatomic, copy, nonnull) int (^completion)(int);
方法形参
-
(void)doSomethingWithBlock:(returnType (^nullability)(parameterTypes))blockName;
举例: -
(void) doSomethingWithCompletion:(int (^_Nullable)(int))blockName;
方法实参
[someObject doSomethingWithBlock:^returnType (parameters) {...}];
举例:
[a doSomethingWithCompletion:^int (int) {
// ...
}];
类型定义
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {
// ...
};
举例:
typedef int (^Handler)(int);
Handler handler = ^int(int) {
// ...
};
最后,Enjoy yourself!
作者:coderanger
链接:https://www.jianshu.com/p/a1aa24693f2e
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论