I have two versions of my model Model001.xcdatamodel and Model002.xcdatamodel. These two are in the Model.xcdatamodeld bundle.
I also have a Model001to002.xcmappingmodel which is not part of the Model.xcdatamodeld. I checked: both the xcmappingmodel and the xcdatamodeld get copied into the .app bundle.
My managed object context is initialized like this:
NSURL *documentModel = [bundle URLForResource:@"Model" withExtension:@"momd"]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:documentModel]; return managedObjectModel;
I also set these properties on my overridden initWithFileURL: in my UIManagedObject subclass.
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:self.persistentStoreOptions]; [options setObject:@YES forKey:NSMigratePersistentStoresAutomaticallyOption]; [options setObject:@YES forKey:NSInferMappingModelAutomaticallyOption]; self.persistentStoreOptions = [options copy];
But when I try to open a documet, I get the following error:
Can't find mapping model for migration
-- UPDATE --
Even if I do a manual migration
[NSMappingModel mappingModelFromBundles:@[[NSBundle mainBundle]] forSourceModel:sourceObjectModel destinationModel:self.managedObjectModel];
this returns nil. Although I double checked that the Model001to002.cdm is in the app bundle. It has to be in the app bundle right?