libextobjcを使用すると、読みやすく簡単になります。
- (void)doStuff
{
@weakify(self);
// __weak __typeof__(self) self_weak_ = self;
[self doSomeAsyncStuff:^{
@strongify(self);
// __strong __typeof__(self) self = self_weak_;
// now you don't run the risk of self being deallocated
// whilst doing stuff inside this block
// But there's a chance that self was already deallocated, so
// you could want to check if self == nil
[self doSomeAwesomeStuff];
[self doSomeOtherAsyncStuff:^{
@strongify(self);
// __strong __typeof__(self) self = self_weak_;
// now you don't run the risk of self being deallocated
// whilst doing stuff inside this block
// Again, there's a chance that self was already deallocated, so
// you could want to check if self == nil
[self doSomeAwesomeStuff];
}];
}];
}