有一堆关于所有这些薄弱和强大的自我的问题,但我想,你们在我的特殊例子接过来一看:弱和强烈的自我使用,块存储管理
- (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