关闭

block小结--02 block的种类;

标签: block
54人阅读 评论(0) 收藏 举报
分类:

验证block是属于哪类的block;

--------------------------------------------------------------------------------------------------------------------

NSGlobalBlock 

--------------------------------------------------------------------------------------------------------------------

验证:不引用外部的变量就是globalBlock

        //有参数,有返回值------num,num1可以省略;

        int(^blo3)(int num,int num1 ) = ^(int num1,int num2){

            NSLog(@"blo3内部返回的值 %d",(num2+num1)/2);

            return num1 + num2;

        };

        NSLog(@"%d",blo3(30,40));

        

        NSLog(@"%@",blo3 );  //<__NSGlobalBlock__: 0x100002110>


--------------------------------------------------------------------------------------------------------------------

2016-05-31 19:15:58.721 总结--block[6054:847379] blo3内部返回的值 35

2016-05-31 19:15:58.722 总结--block[6054:847379] 70

2016-05-31 19:15:58.722 总结--block[6054:847379] <__NSGlobalBlock__: 0x100002110>


--------------------------------------------------------------------------------------------------------------------

__NSMallocBlock__ 

--------------------------------------------------------------------------------------------------------------------


        __block int a = 10;

        int(^blo3)(int num,int num1 ) = ^(int num1,int num2){

            NSLog(@"blo3内部返回的值 %d",(num2+num1)/2);

            a = 20;

//            NSLog(@"%d",a);

            return num1 + num2;

        };

        NSLog(@"%d",blo3(30,40));

        

        NSLog(@"引用外部变量int a之后-----%@",blo3 );//引用外部变量int a之后-----<__NSMallocBlock__: 0x100601270>



--------------------------------------------------------------------------------------------------------------------

__NSStackBlock__ 

--------------------------------------------------------------------------------------------------------------------

        int a = 10;

        

        NSLog(@"stack-----%@",^{

            NSLog(@"%d",a);

        });

--------------------------------------------------------------------------------------------------------------------

       //stack-----<__NSStackBlock__: 0x7fff5fbff6d8>


--------------------------------------------------------------------------------------------------------------------

--------------------------------------------汇总------------------------------------------------------------------------


        

        NSLog(@"gloal-----%@",^{

            NSLog(@"aaa");

        });

        

       int a = 10;

        void (^block5)() = ^(){

            NSLog(@"%d",a);

        };

        

        NSLog(@"malloc----%@",block5);

        

        

        NSLog(@"stack-----%@",^{

            NSLog(@"%d",a);

        });


--------------------------------------------汇总------------------------------------------------------------------------

2016-05-31 19:55:36.423 总结--block[6228:862567] malloc----<__NSMallocBlock__: 0x1002005c0>

2016-05-31 19:55:36.423 总结--block[6228:862567] gloal-----<__NSGlobalBlock__: 0x1000021c0>

2016-05-31 19:55:36.423 总结--block[6228:862567] stack-----<__NSStackBlock__: 0x7fff5fbff6d8>








0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:74次
    • 积分:20
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档