__
weak
typeof(
self) weakSelf =
self;
dispatch_block_t block = ^{
[weakSelf doSomething];
// weakSelf != nil
// preemption, weakSelf turned nil
[weakSelf doSomethingElse];
// weakSelf == nil
};
最好这样调用:
__
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;
}
};
weak typeof
最新推荐文章于 2020-07-14 11:14:18 发布