//author
//jeffasd
//Block 用法小解
//A.h文件
//定义Block
typedef void(^ AmountBlock)(int salary); //定义一个AmountBlock类型的Block
@property(nonatomic, copy)AmoutBlock amount2; //用AmountBlock类型定义Block 变量
- (void)paySalaryForStaff : (int)staffId withMoney : (AmountBlock)amount;
A.m
- (void)paySalaryForStaff : (int)staffId withMoney : (AmountBlock)amount{
if (staffId == 1)
{
amount(1000);//触发此Block
}
}
B.m文件
- (void)spendMoney{
[a paySalaryForStaff : 01 amount : ^ (int salary){
if (salary = 1000)
{
NSLog(@"hello");
}
}];
}
//------------------------------------------------------------------------
A.h
- (void)paySalaryForStaff:(int)staffId;
A.m
- (void)paySalaryForStaff : (int)staffId{
if (staffId == 1)
{
self.amount(1000);//触发此Block
}
}
B.m
- (void)spendMoney{
a.amount = ^ (int salary){
if (salary = 1000)
{
NSLog(@"hello");
}
}
}
阅读(707) | 评论(0) | 转发(0) |