有一堆關於所有這些薄弱和強大的自我的問題,但我想,你們在我的特殊例子接過來一看:弱和強烈的自我使用,塊存儲管理
- (void)getItemsWithCompletionHandler:(void (^)(NSArray*items))completionHandler {
__weak __typeof__(self) weakSelf = self;
[self doWorkWithCompletionHandler:^(Response *response) {
// this completion is not on main thread
dispatch_async(dispatch_get_main_queue(), ^{
...
[weakSelf doAnotherWorkWithCompletionHandler:^(Response *response) {
// this completions is not on main thread either
dispatch_async(dispatch_get_main_queue(), ^{
__typeof__(self) strongSelf = weakSelf;
NSArray *itemsIds = [strongSelf doWorkOnMainThread1];
NSArray *items = [strongSelf doWorkOnMainThread2];
completionHandler(items);
});
}];
});
}];
}
是一切正確的位置或不?也歡迎您提出重構建議
這個問題可能會更好地排序在[Codereview](http://codereview.stackexchange.com/) –
在外部局部範圍內聲明'itemsIds'和'items'有什麼意義?這不是那個範圍在異步操作中分配給這兩個變量時會存在。 – newacct
是什麼讓你覺得你需要弱引用? – newacct