找不到迁移的映射模型 - UIManagedDocument Core Data Migration [英] Can't find mapping model for migration - UIManagedDocument Core Data Migration
问题描述
我有两个版本的模型 Model001.xcdatamodel
和 Model002.xcdatamodel
。这两个在 Model.xcdatamodeld
包。
我还有一个 Model001to002.xcmappingmodel
,它不是 Model.xcdatamodeld
的一部分。我检查:xcmappingmodel和xcdatamodeld被复制到.app包。
I have two versions of my model Model001.xcdatamodel
and Model002.xcdatamodel
. These two are in the Model.xcdatamodeld
bundle.
I also have a Model001to002.xcmappingmodel
which is not part of the Model.xcdatamodeld
. I checked: both the xcmappingmodel and the xcdatamodeld get copied into the .app bundle.
我的管理对象上下文初始化如下:
My managed object context is initialized like this:
NSURL *documentModel = [bundle URLForResource:@"Model"
withExtension:@"momd"]; managedObjectModel = [[NSManagedObjectModel alloc]
initWithContentsOfURL:documentModel]; return managedObjectModel;
我也设置了这些属性覆盖 initWithFileURL:在
UIManagedObject
子类中。
I also set these properties on my overridden initWithFileURL:
in my UIManagedObject
subclass.
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:self.persistentStoreOptions];
[options setObject:@YES forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setObject:@YES forKey:NSInferMappingModelAutomaticallyOption];
self.persistentStoreOptions = [options copy];
但是当我尝试打开documet时,错误:
找不到迁移的映射模型
But when I try to open a documet, I get the following error:
Can't find mapping model for migration
- UPDATE -
-- UPDATE --
即使我进行手动迁移
[NSMappingModel mappingModelFromBundles:@[[NSBundle mainBundle]]
forSourceModel:sourceObjectModel
destinationModel:self.managedObjectModel];
虽然我仔细检查Model001to002.cdm是否在应用程序包中。
this returns nil. Although I double checked that the Model001to002.cdm is in the app bundle. It has to be in the app bundle right?
推荐答案
确定,通过从Xcode中删除所有核心数据文件,解决问题并重新设置映射模型的源和目标。
OK, solved the problem by removing all core data files from Xcode, reading them and setting the source and destination of the mapping model again.
损坏Xcode!
这篇关于找不到迁移的映射模型 - UIManagedDocument Core Data Migration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!