I just created a new version of my core data model with an extra object along with reworked relationships.
I now now have both files, Medical_Codes.xcdatamodel and Medical_Codes_ 2.xcdatamodel.
Do I have to delete the old NSManagedObject class files and recreate them?
Do I have to change my persistent store code?
- (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;
}