Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've now found out that this is quite simple - once you know where to look.</p> <p>In my AppDelegate I set-up the NSPersistentStoreCoordinator - and you need to add some options to this to tell it to handle auto-migrate:</p> <pre><code>NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error; _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) { // Handle error NSLog(@"Problem with PersistentStoreCoordinator: %@",error); } </code></pre> <p>Then you need to do a little trick in xCode:</p> <ol> <li>Select your xcdatamodel file</li> <li>Select the Design Menu at the top - then Data Model - then choose Add Model Version</li> <li>Your xcdatamodel file will then get moved into a new directory with the same name as your xcdatamodel file but with the extension xcdatamodeld - there will be a second file in this directory with a 2 in the name. Select the new file and then Design->Data Model->Set Current Version (<a href="https://stackoverflow.com/questions/5372479/xcode-4-core-data-model-version-set-current-version">in Xcode 4 you do this</a>)</li> <li>If you have already made the changes that have caused your project to be incompatible - take these changes out of the original xcdatamodel file. If you have yet to make the changes - then just edit the 2.xcdatamodel file (the one you just made current version).</li> <li>Now when you install this version onto a device that has the old model - it will automatically upgrade that model to the new model.</li> </ol> <p>This seems great and as simple as I wanted - but I think you need to be careful during development as you change a model - otherwise you will have to create a new version for each change. </p> <p>I think what I will do is that I will keep all of the changed files and then once I get ready to deploy my update I'll delete all the in-between files and just deploy with the oldest and latest models.</p> <hr> <p>UPDATE (15/07/2011):</p> <p>Thanks to @<a href="https://stackoverflow.com/users/623673/rockstarberlin">rockstarberlin</a> for pointing out there is updated documentation at apple:</p> <p><a href="http://developer.apple.com/library/mac/#recipes/xcode_help-core_data_modeling_tool/Articles/setting_current_version.html" rel="nofollow noreferrer">Xcode 4: Setting a Managed Object Model’s Current Version</a></p> <p>Update: 8/19/2013 better link:</p> <p><a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmModelFormat.html" rel="nofollow noreferrer">https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmModelFormat.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload