Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Core Data Deep Dive: Cant find "Pun" entity with entityForName:@"Pun"

I'm getting this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Pun''

When a run the app using an all exceptions breakpoint then it appears that this line is throwing the error:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pun" inManagedObjectContext:self.managedObjectContext];

It's as if the "Pun" entity doesn't exist, but it I have it and it has a name and is assigned the Pun class.

There something happening outside of the implementation of ListViewController because I copied Amit's ListViewController.m code into my file and I'm still getting the error.

1 Answer

Well...after comparing my code to the project files listed here, I found I missed a step early on. I forgot to implement the managedObjectContext method in AppDelegate.m so my app was not creating an instance of a Managed Object Context.

It's a good thing Xcode creates this for for you in a Master/Detail record with Core Data checked.