iOS Block定义方式
第一种定义场景
typedef void(^TestBlock)(void);
typedef BOOL(^TestBOOLBlock)(void);
typedef BOOL(^TestBOOLResultBlock)(BOOL result);
@interface ViewController ()
@property(nonatomic,copy)TestBlock testBlock;
@property(nonatomic,copy)TestBOOLBlock testBOOLBlock;
@property(nonatomic,copy)TestBOOLResultBlock testBOOLResultBlock;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.testBlock = ^(){
NSLog(@"testBlock");
}
self.testBlock();
self.testBOOLBlock = ^BOOL{
NSLog(@"testBlock");
}
self.testBOOLBlock();
self.testBlock = ^BOOL (BOOL result){
NSLog(@"testBlock");
}
self.testBOOLResultBlock(YES);
}
第二种定义场景
@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();
}
}