CoreData Model Change: Retro Compatibility

I came across this problem with coredata and it made me nuts because it should be straight ahead

I am currently working on the first release of this application, it is obvious that I continue to fake the main data model here and there,

However, every time I change the underlying data model, I need to uninstall the application and reinstall the new version.

It is easy, but only after I was released. I need to change the application update without reinstalling my users.

What am I missing

Is there any code I need to write to provide basic data on how to change existing persistent data to a new one?

thanks for the help

Jason

+2
source share
2 answers

The main data model - migration - adding new attributes / fields to the current data model - no RESET simulator or application required

Steps:

1) Create a model version from the editor. Give her some meaningful name like ModelVersion2

2) Go to this version of the model and make changes to your model.

3) Now go to YourProjectModel.xcdatamodeld and install the current version on the new version.

4) Add the code below to indicate where you are creating the permanent coordinator -

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; 

and set the parameter values ​​as method parameters -

 [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error] 

In my case, it looks something like this:

 - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (__persistentStoreCoordinator != nil) { return__persistentStoreCoordinator; } NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"LGDataModel.sqlite"]; NSError *error = nil; __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (! [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return__persistentStoreCoordinator; } 

Link: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmInitiating.html#//apple_ref/doc/uid/TP40004399-CH7-SW1

+6
source

You need to read Versioning and Migration of Master Data . Here is a blog post that explains this well:

http://www.timisted.net/blog/archive/core-data-migration/

+3
source

All Articles