Core Dataアプリケーションがあり、コアデータモデルを移行(アップグレード)しています。新しいバージョンを作成するたびに、バージョンごとにマッピングモデルを作成します。現在、16のバージョンがあり、次のようなマッピングモデルがあります:1to2.xcmappingmodel 2to3.xcmappingmodel3to4.xcmappingmodel...など。16まで
これは正常に機能しますが、1人のユーザーがバージョン10のデータファイルを持っていて、バージョン16のアプリケーションを更新すると問題が発生します。CoreDataが自動的に10から16にアップグレードされると思ったのですが、「Missingマッピングモデル」。マッピングモデルが正しいことを確認するために、各バージョンに1つずつアップグレードして(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]){
誰かがこれをアップグレードする方法を知っていますか?ありがとうございました。