我想知道这是否是让嵌套块在Objective C中处理同一变量而不导致任何内存问题或ARC崩溃的正确方法。它以 ASIHttpRequest 完成块开始。
MyObject *object = [dataSet objectAtIndex:i];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:@"FOO"];
__block MyObject *mutableObject = object;
[request setCompleteBlock:^{
mutableObject.data = request.responseData;
__block MyObject *gcdMutableObject = mutableObject;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
[gcdMutableObject doLongComputation];
dispatch_async(dispatch_get_main_queue(),^{
[self updateGUIWithObject:gcdMutableObject];
});
});
[request startAsynchronous];
我主要关心的是嵌套调度队列并使用前一个队列的 __block 版本来访问数据。我所做的安全吗?