Reputation: 726
I was chugging along just fine with a project that uses core data for months now since I wired in the core data stack and migrated the database and last night just started getting an error on the Managed Object Model.
I know that what it is doing is trying to establish a managed object context in this line
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Question" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
The program is crashing in the first view controller when it tries to get the Question entity. I declare/create the AppDelegate
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"PSQ" ofType:@"momd"];
NSURL *momURL = [NSURL fileURLWithPath:path];
managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
//managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
When I set a breakpoint in the app delegate, it never gets there before the app crashes. It goes to the view controller first.
The weird thing is, I did not change my core data functionality for about 6 weeks since it was finished and working.
Any ideas what I might be doing?
This began happening while i was adding NSUSerdefaults for an NSSwitch to toggle the option to display an into screen or not.
Update: The app crashes at the point mentioned only in the iPhone version and goes through the managed object issues just fine in iPad. What would be in the .xib files that would be different causing the flow to error at the managedObjectContext
?
Upvotes: 0
Views: 2742
Reputation: 726
Ok got it fixed.
Turns out that somehow the app delegate got rewired in my iphone nib. I guess that is what Xcode was trying to tell me when it would hit up the mainViewController before the app delegate for the managed object context.
I set the class back to UIApplication, then wired the delegate to the app delegate in IB and all is well.
Upvotes: 1