有人喜欢协议,有人喜欢Block,但是根据需求要嵌套Block,即Block里面有Block.我百度了好想没有我想要的答案,然后灵光一闪蒙对了.
在ViewController.m中
- (void)viewDidLoad {
[super viewDidLoad];
//嵌套Block
[self nestBlockWithBlock:^{
NSLog(@"你好");
}];
}
typedef void (^ BlockClass)(int);
-(void)nestBlockWithBlock:(void(^)())block{
BlockClass blockClass = ^(int a){
NSLog(@"%d",a);
block();
};
blockClass(100);
}