我有核心数据应用程序,我一直在迁移(升级)核心数据模型。每次创建新版本时,我都会为每个版本创建一个映射模型。 现在我有16个版本,我有这样的映射模型: 1to2.xcmappingmodel 2to3.xcmappingmodel 3to4.xcmappingmodel ...等等。最多16在核心数据中迁移几个版本
这工作正常,但是当一个用户拥有版本10的数据文件并更新了版本为16的应用程序时会出现问题。我认为Core Data会自动从10升级到16,但是错误显示“缺少映射模型”。为了确保映射模型的正确性,我将它逐一升级到每个版本(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]];
而且我在这里定义的迁移自动选项:
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]){
有谁知道如何升级呢? 谢谢。
是谢谢你...我只是发现它在马库斯Zarra核心数据的书......他写了一大步骤,从每个模型迁移到下一个无需编写额外的映射模型。去检查NSINfersMappingModel谢谢! – 2010-11-30 00:02:37