现在我有16个版本,我有这样的映射模型:
1to2.xcmapPingmodel
2to3.xcmapPingmodel
3to4.xcmapPingmodel
…等等.最多16
这样可以正常工作,但是当一个用户拥有版本10的数据文件并更新具有版本16的应用程序时会出现问题.有些我认为Core Data会自动从10升级到16,但是出现错误显示“Missing”映射模型“.为了确保映射模型在正确的位置,我将它逐个升级到每个版本(10到11,11到12等等),它确实有效……
这是我的代码.
我用这段代码指定模型版本:
NSBundle *modelWrapper = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"TaskApp_DataModel" ofType:@"momd"]];Nsstring *modelPath = [modelWrapper pathForResource:@"TaskApp_DataModel 16" ofType:@"mom"];NSLog(@"%@",modelPath);managedobjectModel = [[NSManagedobjectModel alloc]initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
我在这里定义了Migrate automatic选项:
NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"storedata-sql"]];NSMutableDictionary *dict = [NSMutableDictionary dictionary];[dict setobject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresautomaticallyOption];if (![persistentStoreCoordinator addPersistentStoreWithType:NSsqliteStoreType configuration:nil URL:url options:dict error:&error]){
有谁知道如何升级这个?
谢谢.
如果是这样,您可能需要开始制作新的迁移地图,如果您之前没有尝试过,也可能值得启用自动迁移,因为它可以非常好地填补空白.我觉得是这样的:
[dict setobject:[NSNumber numberWithBool:YES] forKey:NSInfersMapPingModel];
但你必须仔细检查一下.
很抱歉成为坏消息的使者
总结以上是内存溢出为你收集整理的cocoa – 迁移核心数据中的多个版本全部内容,希望文章能够帮你解决cocoa – 迁移核心数据中的多个版本所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)