【iOS】如何在Objective-C中声明Block?

How Do I Declare A Block in Objective-C?

局部变量:

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) {...};
 
原文地址:http://fuckingblocksyntax.com/
posted @ 2015-11-21 23:55  Mr轨迹  阅读(263)  评论(0编辑  收藏  举报