'+entityForName: nil is not a legal NSManagedObjectContext parameter - Core Data '+entityForName: nil is not a legal NSManagedObjectContext parameter - Core Data ios ios

'+entityForName: nil is not a legal NSManagedObjectContext parameter - Core Data


I had forgotten to pass the context to the view controller. Rookie error.


You can pass the context by including the following code before you begin to fetch the data form the database:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];context = [appDelegate managedObjectContext];


If you are using segues you will get the same problems if you don't pass the context down the line. Use this code in the prepareForSegue method of class initiating the segue:

[[segue destinationViewController] setManagedObjectContext:self.managedObjectContext];

That assumes you hold your context in a property called "managedObjectContext" of course.