//初始化一個代碼塊,當參數為空時,可以在空格中寫void 也可以不寫,返回值如果沒有,必須為void
int (^square_num)(int count)=^(int count){
return count*count;
};
//使用代碼塊的時候去掉冥操作符
int result=square_num(5);
NSLog(@"%i",result);
//匿名代碼塊
void(^print_block)()=^{
printf("this is a block");
};
print_block();
typedef int(^SQUARE_NUM)(int count);
SQUARE_NUM s=^(int count){
return count*count;
};
NSLog(@"%i",s(8));聲明:
返回參數 ^函數名)參數)
定義:
^參數){ };
調用:
函數名參數)
本文出自 “JAVA積累” 博客,請務必保留此出處http://linwb.blog.51cto.com/5577836/1288519