objective-c block的几种写法

2019-05-24  本文已影响0人  hwhjxjs
1、作为局部变量

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

2、作为类的属性

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

3、方法参数

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

4、调用方法是传入的参数

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

5、自定义Block类型时

typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
上一篇下一篇

猜你喜欢

热点阅读