Been having my first crack at Core Data and I\'m getting the following error when running my code on my device, but it works fine on the simulator..
*
I just had a similar problem upgrading from IOS5 to IOS6. Turns out it was a case sensitive issue with the model name.
Not sure if this helps anyone.
I had the same problem. The solution was a mix of 2 answers:
1) I had to add the "subdirectory" parameter into the URLForResource call
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"DATAMODEL_NAME" withExtension:@"mom" subdirectory:@"DATAMODEL_NAME.momd"];
2) For a reason I don't know, the data model was not included when the project was compiled. I had to add it manually into the "Build Phases / Compile resources".
With only one of the above solutions, my application didn't work.
On my side the problem was that I'd changed the case of a couple of characters in the database name.
When starting a new project, Xcode automatically sets everything up from the project name. If you started out calling your project "Rugbyontv" and later decided to change to "RugbyOnTV" and did a search and replace, that would break it. (Credit to Rob for pointing out that the name is case-sensitive)
I have been looking an answer for hours and nothing worked. But then I suddenly found this article. So according to this, the problem was in setting root controller in this part of AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
ListViewController *rootView = (ListViewController *)self.window.rootViewController;
rootView.managedObjectContext = self.managedObjectContext;
return YES;
}
In fact you should define what root controller will delegate your CoreData connection. And in my case I had a TabBarController connected to other views, so my targed view root controller was defined as TabBar and it caused an error. I changed
ListViewController *rootView = (ListViewController *)self.window.rootViewController;
to
ListViewController *rootView = (ListViewController *)self.window.superview;
and everything worked.
Another source of this error, is that sometimes Xcode doesn't include the data model in the build.
Check the Build Phases of your target, and ensure that the *.xcdatamodeld file is included in the Compile Sources section.
I had exactly the same error message as the original post. I was wrestling with this for hours. It was this line in my AppDelegate.m.
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"[same with name of xcdatamodeld]" withExtension:@"momd"];
For anyone out there searching this error message and finding this thread....try this first.
You must make sure that where it says [same with name of xcdatamodeld]....that it is!!! For some reason, mine had my project name in there and not the data model name.
Changed it and it worked straight away.....
Thanks to Rock & Muller for contributing.......you saved me days!!
Gaz.