iOS中的block模板
总结与记录block的语法使用
局部变量:
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
类属性(property):
@property (nonatomic, copy) returnType (^blockName)(parameterTypes);
方法声明中的参数:
- (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;
方法调用中的参数:
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
typedef的方式:
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
仔细观察上面的block使用规范,可以总结出: