码迷,mamicode.com
首页 > 其他好文 > 详细

Referring to weak self inside a nested block

时间:2015-08-30 17:11:47      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

Your code will work fine: the weak reference will not cause a retain cycle as you explicitly instruct ARC not to increase the retainCount of your weak object. For best practice, however, you should create a strong reference of your object using the weak one. This won‘t create a retain cycle either as the strong pointer within the block will only exist until the block completes (it‘s only scope is the block itself).

__weak typeof(self) weakSelf = self;
[self doABlockOperation:^{
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (strongSelf) {
        ...
    }
}];

Referring to weak self inside a nested block

标签:

原文地址:http://www.cnblogs.com/pencilCool/p/4771143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!