开发者

iPhone: core data error: +entityForName: could not locate an NSManagedObjectModel for entity name 'Name' [duplicate]

This question already has answers here: 开发者_如何转开发 Closed 10 years ago.

Possible Duplicate:

insertNewObjectForEntityForName:

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];
}


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?!


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜