我有一个带有单个持久存储的现有数据模型,一切都很好。
现在,在 WWDC 2012 视频“使用 iCloud 与核心数据”(#227)之后,我在我的模型中定义了两个配置,“云”和“本地”,同时保持原来的“默认”。我已经将我的实体分为“云”和“本地”。在我的代码中,我只添加了两个相应的持久存储:
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES,
NSInferMappingModelAutomaticallyOption: @YES};
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:@"Cloud"
URL:[self cloudPersistentStoreURL]
options:options
error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:@"Local"
URL:[self localPersistentStoreURL]
options:options
error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
这些添加就好了。后来,在运行应用程序时,我尝试正常保存一些初始试用数据,抛出以下异常:
NSUnderlyingException=无法解析如何将对象分配给商店;某些对象可能已分配给商店;使用 [[managedObject objectID] persistentStore] 找出现在的情况;使用 [managedObjectContext assignObject:toStore:] 来理顺事情
我用谷歌搜索了其中的一部分,没有任何点击,Apple 的故障排除核心数据文档似乎没有讨论这个问题。我不知道是什么原因造成的,也不知道去哪里找。有什么想法吗?