I am trying to add core data functionality to an existing project. I added a data model file named "myProj.xcdatamodel"
My code crashes in the following when getting the managedObjectModel What is the "momd" file? where can i get it or how can i create it? When i read the path it returns null and crashes the app.
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"myProj" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
Get our help adding Core Data to your project So, with your existing project open, create a new project in Xcode (⇧⌘N) and select a Single View App, you can call it whatever you like as we'll be deleting it when we're done. You'll see the “Use Core Data” checkbox on the project options screen, make sure it is checked.
Overview. After you create a data model file as described in Creating a Core Data Model, set up the classes that collaboratively support your app's model layer. These classes are referred to collectively as the Core Data stack.
The momd file is the versioned equivalent of the mom file. You have two options at this point:
Only use the non versioned model file. Change your supplied code to:
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"myProj" ofType:@"mom"]; NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
If you create a Navigation-based application (Use Core Data for storage) from the default template in Xcode, you'll notice the model file is already versioned.
For further information see: Model Versions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With