views:

178

answers:

1

Hi,

I did some changes to my model (but I don't want migration yet, so I just remove the application, built clean etc.)

However, when I run it on the iPhone or in the simulator, I get the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'

I set the entity like this:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Document" inManagedObjectContext:managedObjectContext];

My managedObjectContext is not nil. But I suspect that it doesn't load the object model correctly or something similar because If I display the entities in the model, the list is empty:

managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
NSLog(@"%d", [[managedObjectModel entities] count]);

How can I make sure the model is loaded?

Thanks,

A: 

Where are you "displaying the entities"? If they don't show up in the data model editor, they aren't there.

You can use -[NSManagedObjectModel entities] to get an array of the entities that the model has.

In turn, you can use -[NSPersistentStore managedObjectModel] to see what model is loaded and then query its entities.

Gotta tell you however, most of the time this error is caused by a spelling typo. That's why its good to use defines or class methods to return entity names.

TechZen
The entities definitely show up in the entity editor.I display the entities by printing the count of [NSManagedObjectModel entities]. It's empty. For the typo I will double-check but I didn't change anything in the code. I just added some fields in my model.
Kamchatka
The simplest explanation for the empty model is that the changed model is not being compiled into the app for some reason. The store coordinator is being initialized with a blank or nil model.
TechZen