Objective-C声明Block的几种方式

Posted by Srefan on January 5, 2018

一.概述

1. As a local variable:

returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};

2. As a property:

@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);

3. As a method parameter:

- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;

4. As a argument to a method call:

[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

5. As a typedef:

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};

二.参考链接

此文参考于 goshdarnblocksyntax,十分感谢.
所有引用内容版权归原作者所有.
使用 知识共享“署名-非商业性使用-相同方式共享 3.0 中国大陆”许可协议 授权.