I\'m working on an iPhone app that uses Core Data. Most times, I just test in the simulator, but occasionally pump the app down to the iPad to make sure.
I\'ve recen
"Can't merge models with two different entities named 'foo'"
This sounds more like two datamodels beeing merged. Try a clean rebuild of your app. Check if there really is only one datamodel in your project.
The default core data stack loads all data models in your bundle
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
If old models are present all of them are merged.
The persistent store will remain until you delete the app off of your device just like in the simulator. If you really want to start over, then delete the app off of your iPad and it will use the new model.
However as everyone else has pointed out, that is not the error you are getting, Do a clean build of your application (meaning select Build -> Clean from the menu in Xcode) and do a fresh build. If the error still remains then you have more than one xcdatamodel
file being compiled in your project.
For those who come across this question after trying to use core data lightweight migrations:
I was having this issue even after following the instructions for creating a new version of my data model. I noticed that there were two ".mom" files in my application bundle, one ".mom" and one ".momd" directory that contained ".mom" files.
The key is to replace the implementation of - (NSManagedObjectModel *)managedObjectModel
that is generated for you with this implementation:
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"Foo" ofType:@"momd"];
NSURL *momURL = [NSURL fileURLWithPath:path];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
return managedObjectModel; }
where 'Foo' is the name of your data model.
Hopefully this is useful to someone - I spent WAY too many hours beating my head against the wall on this. Thanks again, Apple! :)