Reputation: 8794
When I create a new project with CoreDataModel created by XCode, all is well. However, I added a core model file to my project and the "core data stack" code. The code is properly getting invoked, however, the model's URL is nil. I have tried to examine the project and cannot determine if the model file is not properly added, or compiled, or if the URL just cannot be found.
Help me debug and resolve.
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
modelUrl returns as nil
.
Upvotes: 2
Views: 1506
Reputation: 80265
Check for correct names, then click on the Model.momd
file in the file inspector on the left. In the file attributes inspector on the right make sure it is added to the correct target you are running (i.e. the checkmark beside your target name is checked).
If you cannot find the file in the first place, you have not added it to the bundle correctly. Drag it from the Finder window into your project.
Another hint: note that the there are always at least two files: the directory and the model(s) inside. But you cannot see that if there is only one model version.
Model.xcdatamodeld
Model.xcdatamodel
Make sure that both files in the Finder have the same name before adding the directory to your project. (The directory will show up as a single file.)
Upvotes: 2