/**spa
* block的形式.net
int a = 10;3d
返回值類型 (^變量名)(參數1, 參數2) = ^(參數1,參數2){};orm
*ip
* @return <#return value description#>get
*/it
}io
#pragma mark - 有參數有返回值的blockclass
- (void)test4 {test
int (^block4)(int number1,int number2) = ^(int number1,int number2){
return number1+number2;
};
NSLog(@"%d",block4(4,4));
}
#pragma mark - 有參數無返回值的block
- (void)test3 {
void (^block3)(int number) = ^(int number){
for (int i = 0; i < number; i++) {
NSLog(@"去吃麻辣燙吧......");
}
};
block3(5);
}
#pragma mark - 無參數有返回值的block
- (void)test2 {
int (^block2)() = ^(){
return 10+10;
};
int a = block2();
NSLog(@"%d",a);
}
#pragma mark - 無參數無返回值的block
- (void)test {
void (^block)() = ^(){
NSLog(@"餓死了,吃飯去了......");
};
block();
}