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..
*
first verify:
NSLog(@"%@", [self managedObjectModel]);
If you get a nil value maybe the problem is here
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"RugbyOnTv" withExtension:@"momd"];
So, try changing @"momd" by @"mom"
I solve it by adding the db file to the Copy Bundle Resources
.
Go to root of your project >> select your target >> Build Phases >> Copy Bundle Resources . Make sure your xcdatamodeld file has been added here.
None of the posted solutions worked for me. So, hopefully this post helps someone out there. My app only crashes in release builds btw. Lesson learned. Always test release builds!
BTW, I found this SO post the most helpful https://stackoverflow.com/a/6708837/951349 .
I know this doesn't solve your problem but I ran into this problem yesterday that plagued me for hours, the solution @Dominic Williams posted gave me a ArrayIndexOutOfBoundsException (whatever the Objective-C equivalent is).
I'm not very good with Objective-C/Xcode yet but I'm working on an iOS app that our company had (mostly) developed externally. Unfortunately, they would often forget how to use a keyboard and would use capital letters interchangeably or spell properties incorrectly but were too lazy to go back and change it. They had used a capital letter in the xcode project name where it was not supposed to be (our product name doesn't use a capital) and I had to go back and change every occurence of this upper-case letter to a lower-case; which included the project name, core data file, hundreds of variables, etc.
Anyways, once I had done this I ran into this error and no solution was fixing it for me. I had made sure that all URL names were correct, project cleaned, app uninstalled, phone restarted, etc with no avail. I gave up and turned off my Mac and went home for the day. To my surprise, I came back in this morning and everything seemed to work fine!
I have no idea why this worked but if your stuck, try restarting your Mac.
I am also facing this problem but when i change the ModelName.xcdatamodeld
file it is working. so i think ModelName.xcdatamodeld
file not added to properly, so once check and clean the app and run it.
I faced this same error when i renamed the .xcdatamodel
file from xcode and changed the renamed name in app delegate wherever it was needed, but i still got the same error. None of the suggested procedure worked for me.
Then I opened the folder in Finder
and found an additional file .xccurrentversion
along with .xcdatamodel
file. I opened it up in TextEdit
app and changed this:
<dict>
<key>_XCCurrentVersionName</key>
<string>Your_Renamed_Model_FileName.xcdatamodel</string>
</dict>
I am using this with Xcode 6.4, OSX Yosemite 10.10.1
I hope it helps!
What's probably happened is that your xcdatamodeld file from Apple's source code has turned into a xcdatamodel(without the d) file and therefore they aren't considered the same.
The quickest way to fix this, is to select the xcdatamodel file in your project navigator and in to the menu bar
Editor->Add Model Version...
and add a new version of your model. Make all changes to the new version.
This works in Xcode 5