2つの別々のxcdatamodelファイルで定義されているストアから移行するときに軽量移行を実行する際に問題が発生します。
私のアプリのバージョン1.0では、モデルを分析モデル、モデルA、およびモデルBの他のすべてに分割しました。コンパイル時に、モデルはグループ化され、すべてがスムーズに進行しました。
新しいバージョン1.1で作業しているときに、モデルBに新しいモデルバージョンを追加し、その新しいバージョンをアクティブとして設定することで、モデルBをアップグレードしました。
この問題は、1.0から1.1にアップグレードするときに発生します。Core Dataはディスク上のモデルストア(バージョン1.0で作成)をチェックし、それを説明するモデルを探しますが、ストア全体を定義するSINGLEモデルを見つけることができないようです(モデルAは分析のみをカバーし、モデルBは分析をカバーします)他のすべて)、したがって、「ソースストアのモデルが見つかりません」エラーがスローされます。
モデルを分離するためのソリューションを見つけた人はいますが、カスタム移行を定義するという余分な手間をかけずに、アップグレードと軽量移行を機能させることができますか?
モデルのロードに使用されるコードのスニペットは次のとおりです。
NSArray *modelNames = [NSArray arrayWithObjects:@"model-A", @"model-B", nil];
NSMutableArray *models = [NSMutableArray array];
for (NSString *name in modelNames)
{
LogInfo(@"loading model %@", name);
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:name withExtension:@"momd"];
NSManagedObjectModel *model = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] autorelease];
[models addObject:model];
}
// combine all the separate models into one big one
objectModel = [[NSManagedObjectModel modelByMergingModels:models] retain];
NSURL *documentsDirectory = [NSURL fileURLWithPath:[SuperFileManager documentsDirectory] isDirectory:YES];
NSURL *storeURL = [documentsDirectory URLByAppendingPathComponent:@"database.sqlite"];
NSError *error = nil;
coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:objectModel];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
if (![coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}