I’m following this how-to to implement Core Data storage in my app:
I have a Model.xcdatamodel which defines a Something model. I’ve used XCode to generate a class for that model.
I’ve imported the class in my .m file where I’m trying to:
Something* s = (Something *)[NSEntityDescription insertNewObjectForEntityForName:@"Something" inManagedObjectContext:managedObjectContext];
But this causes the following error:
2009-10-13 21:18:11.961 w9a[4840:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Something''
Am I missing something?
Personally, I prefer the following method:
I’ve noticed it’s less prone to random Core Data errors, and is easier to debug. It’s effectively doing the same thing as your code, but explicitly gets an entity description first, so you can debug that separately if need be.