我是 Core Data 的新手,也是 RestKit。
由于存在一些性能问题,我想在 ios5 中使用并发技术。但是,当它与 RestKit 结合时,就出现了崩溃问题。这是我的崩溃代码:
[[RKObjectManager sharedManager] getObjectsAtPath: HOT_PATH
parameters: params
success:
^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
newContext.parentContext = [self managedContext];
[newContext performBlock:^{
Rumor *rumorInOtherContext = (Rumor *)[mappingResult.array lastObject];;
Rumor *rumor = (Rumor *)[newContext objectWithID:rumorInOtherContext.objectID];
rumor.updateDate = [NSDate date]; // <- crash at this point.
}];
但是,我的代码的旧版本不会崩溃:
[[RKObjectManager sharedManager] getObjectsAtPath: HOT_PATH
parameters: params
success:
^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
Rumor *rumor = (Rumor *)[mappingResult.array lastObject];;
rumor.updateDate = [NSDate date]; // <- save!
}];
控制台对话框中没有出现崩溃报告。:(
我的代码正确吗?或者,是否有其他方法可以做同样的事情?