我已经更新了我的应用程序以支持 iOS 7,并且遇到了在我的一个屏幕上[context save];
出现以下错误的问题:
NSCocoaErrorDomain Code=133020 "The operation couldn’t be completed. (Cocoa error 133020.)" UserInfo=0x1115a6d0 {conflictList=(
"NSMergeConflict (0x1115a670) for NSManagedObject (0xf25c850) with objectID '0xf25c070 <x-coredata://76AF57C8-F7FF-4880-B06B-63F8B780C96D/Screen/p7>' with oldVersion = 5 and newVersion = 6
and old object snapshot = {\n index = 3;\n message = \"<null>\";\n status = 0;\n} and new cached row = {\n index = 3;\n message = \"<null>\";\n status = 0;\n}"
在 iOS6 上不会出现此问题。
更新:managedObjectContext 的代码
-(NSManagedObjectContext *)managedObjectContextForCurrentThread{
if ([NSThread isMainThread])
{
NSManagedObjectContext *parentContext = self.mainManagedObjectContext.parentContext;
[parentContext performBlockAndWait:^{
NSMergePolicy *mergePolicy = [[NSMergePolicy alloc] initWithMergeType:NSMergeByPropertyObjectTrumpMergePolicyType];
[[self mainManagedObjectContext] setMergePolicy:mergePolicy];
}];
return self.mainManagedObjectContext;
}
else
{
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
NSManagedObjectContext *threadContext = [threadDict objectForKey:kCGMManagedObjectContextKey];
if (threadContext == nil)
{
threadContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
NSManagedObjectContext *parentContext = self.mainManagedObjectContext.parentContext;
[parentContext performBlockAndWait:^{
NSMergePolicy *mergePolicy = [[NSMergePolicy alloc] initWithMergeType:NSMergeByPropertyObjectTrumpMergePolicyType];
[parentContext setMergePolicy:mergePolicy];
}];
[threadContext setParentContext:self.mainManagedObjectContext];
[threadDict setObject:threadContext forKey:kCGMManagedObjectContextKey];
}
return threadContext;
}
}