Take the 2-minute tour ×

Possible Duplicate:

See title ^

Code causing this:

NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];

    Name *name = (Name *)[NSEntityDescription insertNewObjectForEntityForName:@"Name" inManagedObjectContext:context];

    Feature *feature = (Features *)[NSEntityDescription insertNewObjectForEntityForName:@"thing" inManagedObjectContext:context];
    [feature setName:app];  
    [name addFeaturesObject:feature];

app is an NSString defined earlier.

Things I've tried:

in viewDidLoad:

 if (managedObjectContext == nil)
    managedObjectContext = [(IsidoreAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
share|improve this question
add comment

marked as duplicate by Tim Cooper, Kev Jul 28 '12 at 13:30


2 Answers

Your managed object context is probably not set and the entity "Name" is obviously not valid for a nil context.

In viewDidLoad, you are setting the "managedObjectContext" instance variable for your view controller by using the app delegate which is fine, but then your problem code is using the managed object context from the fetched results controller. Has that been setup yet?

Also, check out this answer to Core Data and UITabBar Controller - help?!

share|improve this answer
it's all there... –  Matt S. Jan 3 '10 at 16:52
add comment

I've ran into the same issue. I created a separate project in xCode4, using "Navigation Based Application" and "Use Core Data" options. Then I copied over the table view with persistent data over to my other application. This is when I ran into the issue. I've defined the Entity along with all the fields, and then had the +entityForName: could not locate an NSManagedObjectModel for entity name 'Name' error

Good thing is it is rather easy to fix: If you are working along the same path as I did, add this line to your App delegate at the point where you instantiate the controller:

yourViewController.managedObjectContext = self.managedObjectContext;
share|improve this answer
add comment
