我有很多條的品類很多關係的核心數據。試圖保存時,出現以下錯誤。我無法找到有關它的含義的信息,以及數據庫爲空時爲什麼有兩個版本。任何人都可以點亮一下嗎?iOS版:核心數據錯誤:NSMergeConflict爲NSManagedObject
錯誤:NSMergeConflict (0x76ae720) for NSManagedObject (0xd945560) with objectID '0xd943550 <x-coredata://09A438A8-E3F5-45FE-B9D7-106798E82E18/Article/p91>' with oldVersion = 1 and newVersion = 2
代碼:
NSMutableDictionary *dict = [[data objectAtIndex:i] valueForKey:@"category_names"];
NSMutableArray *values = [[NSMutableArray alloc] init];
for (NSString *value in [dict allValues]) {
NSLog(@"value = %@", value);
[values addObject:value];
}
NSMutableSet *setElements = [[NSMutableSet alloc] init];
for (int i = 0; i < [values count]; i++) {
Category *cat = [self getCategoryFor:[values objectAtIndex:i]]; // Function which has fetch to get the category for the value "name"
[setElements addObject:cat];
}
if ([setElements count] > 0)
[article addCategories:setElements];
// Save the context.
NSError* error;
if (![managedObjectContext save:&error]) {
NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
} else
NSLog(@" %@", [error userInfo]);
}
[article release];
[values release];
[setElements release];
謝謝你的幫助。我將數據添加到sqlite,然後將sqlite添加到項目中。這似乎會導致某種類型的版本問題。我加入的代碼所需要的所有數據,採取了DB了模擬器,它添加到項目中,問題就走開了。 – 2010-11-18 16:49:23
這是非常困難的,直接添加數據到核心數據的SQL存儲,因爲它使用它自己的無證架構。 – TechZen 2010-11-18 18:10:07