iOS block 防循环引用

2015-08-29  本文已影响2833人  匿名类

__weak typeof(self) weakSelf = self;

myObj.myBlock = ^{

__strong typeof(self) strongSelf = weakSelf;

if (strongSelf) { [strongSelf doSomething]; // strongSelf != nil

// preemption, strongSelf still not nil(抢占的时候,strongSelf 还是非 nil 的)

[strongSelf doSomethingElse]; // strongSelf != nil }

else { // Probably nothing... return;

}

};

上一篇 下一篇

猜你喜欢

热点阅读