Я теперь узнал, что это довольно просто - когда вы знаете, где искать. #
В моем AppDelegate я настроил NSPersistentStoreCoordinator - и вам нужно добавить некоторые параметры для этого, чтобы он мог обрабатывать автоматическую миграцию:
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:&error]) {
// Handle error
NSLog(@"Problem with PersistentStoreCoordinator: %@",error);
}
Тогда вам нужно сделать в xCode:
1. Select your xcdatamodeld file
2. Select the Editor Menu at the top - then choose Add Model Version
3. Now your xcdatamodeld file have two (modelname.xcdatamodel & modelname2.xcdatamodel ) .
4. Now modelname.xcdatamodel have the green check mark implies it is current version, but we need to change the modelname2.xcdatamodel as a current version
5. Select the xcdatamodeld file and then select the View Menu at the top - then Choose Utilities - then Choose the Show File Inspector is shown in right side of Xcode and then Select the Versioned Core Data Model - have Current(DropDownList) - select modelname2(the one you just made current version have green check mark).
6. Now when you install this version onto a device that has the old model - it will automatically upgrade that model to the new model.
Это кажется великолепным и простым, как я и хотел - но я думаю, что вы должны быть осторожны во время разработки при изменении модели - в противном случае вам придется создавать новую версию для каждого изменения.
Я думаю, что я сделаю то, что я сохраню все измененные файлы, а затем, как только я буду готов к развертыванию своего обновления, я удалю все промежуточные файлы и просто разверну с самыми старыми и последними моделями.