I have a CoreData database which works on the root view controller. I have a second UIViewController of which when I switch to, and use the same exact line to fetch NSEntityDescription, I get the following error:
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: +entityForName: could not locate an NSManagedObjectModel for entity name ‘Channel”
I am doing that as follows:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Channel" inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
The error hits at the NSEntityDescription *entity line. How is this possible if the line works on another UIViewController?
Thank you
The error is suggesting that the
ManagedObjectContexthave a problem.Are you passing your
ManagedObjectContextfrom your first view to the second (if not try it)If this doesn’t work can you post the code where you’re assigning
self.contextYou mean code like this one in your
appDelegatein theawakeFromNibmethod:You need the second line to pass the actual
managedObjectContextYou can put that second line in your
firstViewlike this:Of course you need to set up the necessary
@property.In doing so from
UIViewControllertoUIViewControllerstarting from theappDelegateyou will be passing a reference to that instance ofNSManagedObjectContext.UITabBarController Class Reference is there if you need more information.
Just make sure that when you make the assignment the
IBOutletare set and that yourNSManagedObjecthave been created.