这篇文章在只是列了在平时代码中block的写作方式, 仅仅是作为备忘
- 作为局部变量
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
- 作为属性
@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
- 作为方法变量
- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;
- 作为方法参数
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
- typedef
- 使用typedef可以让block在代码中跟易读
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};