__weak
typeof
(self) weakSelf = self;
myObj.myBlock = ^{
__strong
typeof
(self) strongSelf = weakSelf;
if
(strongSelf) {
[strongSelf doSomething];
// strongSelf != nil
// preemption, strongSelf still not nil
[strongSelf doSomethingElse];
// strongSelf != nil
}
else
{
// Probably nothing...
return
;
}
};
block中需要对weakSelf进行strong,保证代码在执行到block中,self不会被释放,当block执行完后,会自动释放该strongSelf