私は、余分なオブジェクトとリワークされたリレーションシップを持つコアデータモデルの新しいバージョンを作成しました。コアデータモデルの新しいバージョンを追加しますか?
私は現在、Medical_Codes.xcdatamodel
とMedical_Codes_ 2.xcdatamodel
の両方のファイルを持っています。
古いNSManagedObject
クラスファイルを削除して再作成する必要がありますか?
永続的ストアコードを変更する必要はありますか?
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil)
{
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Medical_Codes" withExtension:@"mom"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (__persistentStoreCoordinator != nil)
{
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Medical_Codes.sqlite"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:[storeURL path]])
{
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Medical_Codes" ofType:@"sqlite"];
if (!defaultStorePath)
{
NSLog(@"Error: Could not locate Medical_Codes.sqlite in app bundle");
return nil;
}
NSError *error = nil;
if (![fileManager copyItemAtPath:defaultStorePath toPath:[storeURL path] error:&error])
{
NSLog(@"Error copying sqlite from bundle to documents directory: %@, %@", error, [error userInfo]);
return nil;
}
}
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __persistentStoreCoordinator;
}
これがJonの助けになるかどうかはわかりませんが、これは私が今までに見た中で最高の答えでした。それは間違いなく自分のマイグレーションの問題で私を助けました。 – lukecampbell
ありがとう、私は賛辞を感謝します。私はそれが誰かを助けたことを喜んでいる。 – gschandler
アップルのCore Dataのドキュメントは素晴らしいです。特に、バージョニングの話題については特にそうです。 –