I'm almost finished with my 1.1 release of my first iOS app, in it I have made two small changes to my core data model. More specific, I have added two attributes to one of my tables. This is my first core data app and therefore my first core data update to a live app, and I'm a bit nerveous about shipping code that might not work for my current users. Since it's a small update I'm guessing that Apples automatic migration method will do, but I don't want to guess.
The relevant code looks like this:
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
//NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
In 1.1 I've added NSDictionary *options
.
In my view controller I make sure the the needed rows isn't nil like this:
if (currentPage.inputType == @"drawing") {
[pageView changeToDrawing];
} else if (currentPage.inputType == @"text") {
[pageView changeToText];
} else {
currentPage.inputType = @"text";
[pageView changeToDrawing];
}
Basically, is these changes enough or do I have to do something else?
The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.
The short answer is simple. Core Data is a framework for managing an object graph. SQLite is a relational database.
Here is a very helpful article with regard to Core Data versioning that answers your question.
To sum it up in a few words, you will need to add a new model version to your project. This is necessary for the migration process.
Edit
Link above has changed and will redirect you to the following link: Core Data Model Versioning and Data Migration
If all else fails, google: Core Data Model Versioning and Data Migration apple developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With