How Do I Declare A Block in Objective C
接触OC也有段时间了,对Block
的语法一直有点犯迷糊,结果发现了一个有意思的网站,FuckingBlockSyntax,下面就是这个网站的全部内容,转载一下,供以后查阅。
As a local variable:
1
| returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
|
As a property:
1
| @property (nonatomic, copy) returnType (^blockName)(parameterTypes);
|
As a method parameter:
1
| - (void)someMethodThatTakesABlock:(returnType (^)(parameterTypes))blockName;
|
As an argument to a method call:
1
| [someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
|
As a typedef:
1 2
| typedef returnType (^TypeName)(parameterTypes); TypeName blockName = ^returnType(parameters) {...};
|