///变量
@property (nonatomic,copy,nullable) int (^blockName2) (int,int);
self.blockName2 = ^ int (int a,int b){
return a+b;
};
int a = self.blockName2(2,3);
///定义成参数
int (^blockName)(int) = ^ int (int a){
a += 10;
NSLog(@"block");
return a;
};
[self methodBlock:blockName];
[self methodBlock:^int(int a) {
a+=20;
NSLog(@"block2");
return a;
}];
///当成参数传来
-(void)methodBlock:(int (^)(int a)) blockName{
int a = blockName(2);
NSLog(@"a=%d",a);
}
网友评论