スレッドで MOC を操作する新しい方法を使用しています
問題は、私が呼び出しを使用するときです
[child obtainPermanentIDsForObjects:parsedItemsObjects error:&error];
永久 ID を取得するには...
ブロックを離れる間、私は得る
NSManagedObject Context Queue Serial
i get an EXC_BAD_ACCESS on objc_msgSend
libobjc.A.dylib`objc_msgSend:
0x34eb9f68: teq.w r0, #0
0x34eb9f6c: beq 0x34eb9faa ; objc_msgSend + 66
0x34eb9f6e: push.w {r3, r4}
HERE 0x34eb9f72: ldr r4, [r0]
0x34eb9f74: lsr.w r9, r1, #2
0x34eb9f78: ldr r3, [r4, #8]
...
コード
- (void) parse:(NSDictionary *)serviceResponseDictionary onParseFinished:(ParseFinished)onParseFinished onParseFailed:(ParseFailed)onParseFailed
{
NSManagedObjectContext * parent = [NSManagedObjectContext MR_defaultContext]; // NSMainQueueConcurrencyType
NSManagedObjectContext * child = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[child setParentContext:parent];
[child performBlock:^(){
Class parsedItemsClass = [NSNull class];
NSMutableArray * parsedItemsObjectIDs;
NSMutableArray * parsedItemsObjects;
// processing the serviceResponseDictionary here
// creating / deleting / modifying Managed objects in child here
NSError * error;
[child save:&error];
// handle and check error here
[child obtainPermanentIDsForObjects:parsedItemsObjects error:&error];
// handle and check error here
// obtain pernament IDs here, if remove, it doesnt crash
parsedItemsObjectIDs = [[NSMutableArray alloc] initWithCapacity:[parsedItemsObjects count]];
for (NSManagedObject * mo in parsedItemsObjects) {
[parsedItemsObjectIDs addObject:mo.objectID];
}
[parent performBlock:^(){
NSError * error;
[parent save:&error];
// handle and check error here
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
onParseFinished(parsedItemsClass, parsedItemsObjectIDs);
}];
}];
}];
}