block
2016-07-13 本文已影响0人
火鸡蛋大爷
///变量
@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);
}