« My Sister | Main | Rework from 37signals »
3:20PM

CoreData: could not locate an NSManagedObjectModel for entity name

If you've gone through Apple's Core Data Tutorial for iOS and gotten this error message after trying to copy that functionality into your existing app:

+entityForName: could not locate an NSManagedObjectModel for entity name

you might need to modify the line of code in your application delegate where you load the managed object model.

NSString *modelPath = [[NSBundle mainBundle]      pathForResource:@"AppName"
          ofType:@"momd"];

The steps you're taken through in the tutorial put your object models in an xcdatamodeld directory, whereas if you just add a model to an existing project it goes in an xcdatamodel file. During the build process, xcdatamodeld directories get converted to momd files, but xcdatamodel files by themselves get turned into mom files.

You can fix the problem in two ways:

  1. Change the filename you're opening to be of type mom
  2. Select your model file and go to Design --> Data Model --> Add Model Version. XCode will place your model file and a new model file in a xcdatamodeld directory. Then delete the extra model version until you really need it.

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>