views:

56

answers:

2

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];
A: 

the "mom" or "momd" file is the compiled version of the .xcdatamodel file. Perhaps you didn't add the .xcdatamodel file to the target so it isn't getting compiled? Do Get Info on it and make sure it's building for your target.

Also check out the CoreDataBooks sample code.

Nimrod
+2  A: 

The momd file is the versioned equivalent of the mom file. You have two options at this point:

  1. Add a version to your existing myProj.xcdatamodel model. In Xcode select the myProj.xcdatamodel file and select Design -> Data Model -> Add Model Version from the menu in Xcode.
  2. 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

Chris Gummer
thanks, I'll try this tomorrow when i have access to the code? How anybody suppose to know this? :( couldn't find this in the documentation.
aryaxt
Have a look at the Core Data Versioning and Data Migration Programming Guide - http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/CoreDataVersioning/Articles/vmVersioning.html%23//apple_ref/doc/uid/TP40004714-SW1
Chris Gummer