As the other practice in weak and strong, it recommends that we should check whether the weakself is null before we strongify it. It looks like this:
__weak weakself = self
someblock {
if (weakself) {
__strong self = weakself
[self doSomeAction];
...
}
}
I know rac does a lot of work ahead, but I want to make sure whether it's necessary that we should check it or not. And if not, how does the @strongify(self) do this. Thanks.
No, you should check after strongify
, because it can stop existing till you strongify it.
After strongify it won't stop existing anyway, even check for nil
will not required any synchronizations. I don't know where you did get such invalid recommendations.
if (weakself) { // not nil here
__strong self = weakself //already nil here
[self doSomeAction]; //you don't have retain cycles,
// but there is a potentical crash, for example if you are calling blocks
@strongify do it exactly in such way how you already write, it's just a convenience macro:
__strong typeof(weakSelf) self = weakself
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.