I am trying to setup CoreData in a new project, but somehow am stuck locating the momd directory.
I found several stackoverflow posts with similar questions, but was unable to solve the problem with the supplied answers. So here it is: What causes the first line to return ‘nil’ and the second one actually finds the momd directory?
NSURL *modelURL = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"Project" ofType:@"momd"]
];
NSURL *modelURL = [NSURL fileURLWithPath:
@"/Users/name/Library/Developer/Xcode/DerivedData/Project-afusjhpzsjyjdbesttxposfzlzrj/Build/Products/Debug/Project.app/Contents/MacOS/Project.momd"
];
Edit: As Metabble commented, It’s now logical that the mainbundle is unable to locate resources outside the Resources folder.
But my problem still exists. I found out some more:
I am using mogenerator to generate classes. (I used these instructions: http://www.esenciadev.com/2011/05/mogen-and-xcode4-integration/).
A script is called by a build rule process ‘Data model version files’. In that build rule I’ve set the output to ‘${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.momd’ but it looks like that is not the correct destination for the momd:
error: Could not create bundle folder for versioned model at '/Users/user/Library/Developer/Xcode/DerivedData/Project-afusjhpzsjyjdbesttxposfzlzrj/Build/Products/Debug/Project.app/Contents/MacOS/Project.momd'
If I delete the build rule, the code can find the momd.
But that disables mogenerator…
Anybody know what output files I need to set in the build rule?
Make sure you add a build rule to your project that copies the Project.momd file to your app’s Resource directory.