首页 > 移动平台 > 详细

【iOS】self与block的使用规范

时间:2016-04-05 19:10:17      阅读:259      评论:0      收藏:0      [点我收藏+]

避免block中循环引用,内存释放不了的问题,规范编码很重要。

相对来说,在block中操作self时,正确的使用姿势。

 1 BlockManager *bm = [BlockManager sharedInstance];
 2     
 3 __weak typeof(self) weakSelf = self;
 4 [bm doSomethingWithBlock:^NSString *(NSInteger value) {
 5     __strong typeof(weakSelf) strongSelf = weakSelf;   //不能缺少
 6     if (strongSelf) {
 7         NSLog(@"%@", strongSelf.array[7]);
 8         [strongSelf printMsg];
 9         return @"YES";
10     }
11     
12     return @"NO";
13 }];

 

【iOS】self与block的使用规范

原文:http://www.cnblogs.com/vokie/p/5356124.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!