我正在使用GDCoreDataConcurrencyDebugging
並且我不完全理解我得到的錯誤。我使用AFNetworking
來獲取一些數據,並在成功塊中將響應保存在覈心數據中。核心數據。無效的對管理對象的併發訪問調用'release'
我可以用下面的代碼錯誤:
NSURL *baseURL = ...
AFHTTPRequestOperationManager *operationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
[operationManager GET:@"layouts"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject){
// backgroundManagedObjectContext is of NSPrivateQueueConcurrencyType
NSManagedObjectContext *context = [AppDelegate backgroundManagedObjectContext];
[context performBlock:^{
// Fetch and modify some NSManagedObject
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Layout"];
Layout *layout = [context executeFetchRequest:request error:nil][0];
// Remove this and the error goes away
layout.name = @"foo";
// Or this, and the error goes away
[context save:nil];
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error){}];
錯誤消息從GDCoreDataConcurrencyDebugging
如下:
Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 Econ 0x000000010016fba3 ValidateConcurrency + 346
1 Econ 0x000000010016f85c CustomSubclassRelease + 18
2 CoreFoundation 0x00000001035718eb CFRelease + 603
3 CoreFoundation 0x0000000103580a82 __CFBasicHashDrain + 322
4 CoreFoundation 0x000000010357180c CFRelease + 380
5 CoreFoundation 0x00000001035a2c4d -[__NSDictionaryM dealloc] + 157
6 libobjc.A.dylib 0x0000000102ff128e _ZN11objc_object17sidetable_releaseEb + 236
7 Foundation 0x0000000101261e0b -[NSConcreteNotification dealloc] + 84
8 libobjc.A.dylib 0x0000000102ff128e _ZN11objc_object17sidetable_releaseEb + 236
9 Econ 0x0000000100022e8b __destroy_helper_block_426 + 59
10 libsystem_sim_blocks.dylib 0x000000010608a734 _Block_release + 196
11 CoreData 0x0000000100abbb61 developerSubmittedBlockToNSManagedObjectContextPerform + 433
12 libdispatch.dylib 0x0000000106010614 _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000105ff8a1c _dispatch_main_queue_callback_4CF + 1664
14 CoreFoundation 0x00000001036031f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
15 CoreFoundation 0x00000001035c4dcb __CFRunLoopRun + 2043
16 CoreFoundation 0x00000001035c4366 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x0000000105818a3e GSEventRunModal + 161
18 UIKit 0x0000000101cd1900 UIApplicationMain + 1282
19 Econ 0x00000001000a28ef main + 111
20 libdyld.dylib 0x0000000106044145 start + 1
21 ??? 0x0000000000000003 0x0 + 3
)
我缺少什麼?
看起來像您的後臺託管對象上下文可能忙於其他事情。 – Mundi
它不應該,但如果是這樣,它將如何解釋錯誤信息? – andershqst