// 定义block
//1.无参数无返回值的Block
typedef void(^chengfa)();
//2.有参数无返回值的Block
typedef void(^jianfa)(int a, int b );
//3.有参数有返回值的Block
typedef int(^jiafa)(int a, int b );
// 声明block
@property (nonatomic,strong)jiafa plus;
@property (nonatomic,strong)jianfa jq;
@property (nonatomic,strong)chengfa cheng;
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
self.jq = ^(int a, int b) {
NSLog(@"减法 = %zd",a-b);
};
self.jq(9, 4);
self.plus = ^int(int a, int b) {
return a+b;
};
NSLog(@"加法 = %zd",self.plus(5, 6)) ;
self.cheng = ^{
NSLog(@"无参数无返值");
};
self.cheng();
void (^emptyBlock)() = ^(){
NSLog(@"无参数,无返回值的Block");
};
emptyBlock();
}