I am trying to set up coredata in a project I have already started.. I have gone though some other errors, but have now narrowed it down to this,
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Manuf''
I think I have narrowed down the problem and a possible solution to this question and answer here re: Alex's answer.
However I am not totally sure this is the case for me, as the reason for my confusion is that instead of setting everything up in my app-delegate & viewcontrollers I am actually using my app-delegate & a object class. So I am hoping someone can help me isolate and fix my issue here...
This is the segment of code in my object class thats giving me the issue. It is almost identical to the template code produced by xcode for coredata apps, however its excluding the sorting and tableview stuff because I dont need that.. I am just dumping a bunch of NSData into my coredata object.
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Manuf" inManagedObjectContext:self.managedObjectContext]; //this is the line where my code fails and generates the error in the log
[fetchRequest setEntity:entity];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __fetchedResultsController;
}
UPDATE:
This is where I think I am going wrong. In the template code the controller and the context is set up inside the appdelegate like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
ICDMasterViewController *controller = (ICDMasterViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
and because I am doing all my stuff in a object class I am not sure how to initialize this in my app delegate?
As opposed to what I am trying to do now in my appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Add status bar
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface
self.navigationController.navigationBar.tintColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
//try setting up context for my nsobjectclass EngineResponses
EngineResponses *engineResponses = [[EngineResponses alloc] init];
engineResponses.managedObjectContext = self.managedObjectContext;
return YES;
}