代碼塊block

//初始化一個代碼塊,當參數爲空時,可以在空格中寫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));

聲明:

  返回參數 (^函數名)(參數)

定義:

  ^(參數){ };

調用:

 函數名(參數)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章