I am using Apple\'s CoreDataBooks sample project as a learning aid for core data.
I modified the app so that when the app loads I show a menu page first - not the B
During my development, I could not find Entities that I added later on. What worked for me: (Basically a sanity-tip :-)
Uninstall the App EVERY TIME you change the Data Model!
The Data Model is cached by Core Data between installs, to make sure the integrity stays in tact. Delete the App from the simulator / iPhone to be able to test your changes.
PS: does anyone know how to do that automatically?
Did you change the Core Data model at all? That error is common when the Core Data model for an app changes without also changing the underlying SQLite database, so the stored data and the model are out of sync.
Try completely removing your app from the Simulator or testing device, then reinstalling it and trying again.
In applicationDidFinishLaunching: you're doing the following:
rootViewController.managedObjectContext = self.managedObjectContext;
But I don't see the code where self.managedObjectContext is setup. applicationDidFinishLaunching is called pretty early on. Are you sure you setup the managed object context?
Ok.
Placing the following code inside of the RootViewController's viewDidLoad eliminates the error:
if (managedObjectContext == nil)
{
managedObjectContext = [(CoreDataBooksAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSLog(@"After managedObjectContext: %@", managedObjectContext);
}
I found someone with a similar problem here on SO: link text
As Aryeh pointed out in that post: "In short you are trying to fetch an entity from an objectContext that hadn't been set up yet. Your options therefore are to set it up right then or do elsewhere in the app before this view loads."