我正在尝试升级我当前的应用程序以使用带有专门子实体的抽象父实体。我创建了一个自定义 NSEntityMigrationPolicy,并在映射模型中将自定义策略设置为我的类的名称。
我正在像这样初始化我的持久存储,这应该是相当标准的:
NSError *error=nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Error adding persistent store : %@",[error description]);
NSAssert(error==nil,[error localizedDescription]);
}
当我运行该应用程序时,我收到以下错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“操作无法完成。(可可错误 134140。)'
[error userInfo] 包含“原因=找不到迁移的映射模型”
我已经验证数据模型的版本 1 将打开,如果我设置 NSInferMappingModelAutomaticallyOption 我得到一个迁移,虽然我的实体没有正确迁移(如预期的那样)。
我已经验证了映射模型(cdm)在应用程序包中,但不知何故它拒绝找到它。我还在自定义迁移策略中设置了断点和 NSLog() 语句,无论有没有 NSInferMappingModelAutomaticallyOption,它都不会运行
关于为什么似乎无法找到映射模型的任何提示?