Frage

I'm trying to figure out how to make my app to be able to migrate from one data model version to another.

I read whole bunch of resources online, and figured out that using Magical Record can be really useful, especially MR_coordinatorWithAutoMigratingSqliteStoreNamed method.

Everything looked good until I started to do some testing, when I noticed the app crash under following conditions.

enter image description here

so this is my data model versions...everything works just fine when I work with document version or document4 version...but when I pick document3 version I have this crash:

enter image description here

any kind of help is highly appreciated!

War es hilfreich?

Lösung

When you use migrations, you have to manually create your data model from the .momd bundles. So for your managedObjectModel accessor method that gets created in your application delegate you need to change it slightly from what gets implemented by default:

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
        return managedObjectModel;
    }

    // modified method
    NSString *path = [[NSBundle mainBundle] pathForResource:@"VideoInfo" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

    return managedObjectModel;
}

There's a great explanation of this here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top