iOS Block定义方式
第一种定义场景
typedef void(^TestBlock)(void);
@interface ViewController ()
@property(nonatomic,copy)TestBlock testBlock;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.testBlock = ^(){
NSLog(@"testBlock");
}
self.testBlock();
}
第二种定义场景
@interface ViewController ()
@property(nonatomic,copy)void(^testBlock)(void);
@end
第三种种定义场景
void(^testBlock)(void) = ^(){
};
testBlock(); //执行block
第四种种定义场景
- (void)doSomethingWithComplete:(void(^)(void))completeBlock{
//Some things done
if(completeBlock){
completeBlock();
}
}
网友评论