Reputation: 71
I have a project that uses core data and this error happens intermittently. I know that the entity is there because most the time, the app opens and displays the content of the entityName. 1. this is happening in the app delegate and not being segue'd 2. when i do [self.managedObjectModel entities], the entityName is there but app crashes 3. It is not miss-spelled. 4. It occurs the same place, the same time (app start)
NSManagedObjectContext *contOBJ = self.managedObjectContext;
NSEntityDescription *entity;
NSString * entityForNameString = @"MessageLists";
@try {
entity = [NSEntityDescription entityForName:entityForNameString
inManagedObjectContext:contOBJ];
}
@catch (NSException* exception) {
NSLog(@"DANGER DANGER - ERROR FOUND");
NSLog(@"Uncaught exception: %@", exception.description);
// ditch effort to reset manageObject BUT DOES NOT WORK...
[self.managedObjectContext reset];
// ditch effort to reset manageObject BUT DOES NOT WORK...
return nil;
NSLog(@"Stack trace: %@", [exception callStackSymbols]);
// Reset the store
}
@finally {
NSLog(@"finally");
}
NSFetchRequest *fetcher = [[NSFetchRequest alloc] init];
// need to define a predicate that will institute weather a message thread is deleted or NOT
[fetcher setEntity:entity];
NSError *error;
NSLog(@"All Records is %@",[contOBJ executeFetchRequest:fetcher error:&error]);
return [contOBJ executeFetchRequest:fetcher error:&error];
Upvotes: 0
Views: 36
Reputation: 71
The reason why my issue was intermittent is not because of my codes but rather changes to iOS 10. Apparently, apple made changes to the way core data is init and declared in the AppDelegate.
Starting in iOS 10 and macOS 10.12, the NSPersistentContainer handles the creation of the Core Data stack and offers access to the NSManagedObjectContext as well as a number of convenience methods. Prior to iOS 10 and macOS 10.12, the creation of the Core Data stack was more involved.
As it turns out, even if I implemented:
NSFetchRequest *fetchRequest = [MessageLists fetchRequest];
NSError *error;
NSLog(@"All Records is %@",[context executeFetchRequest:fetchRequest error:&error]);
I would still arrive at the same issue. Besides, I haven't updated my AppDelegate's Core Data codes since iOS 8...
Upvotes: 0
Reputation: 12003
Don't use that old stringly typed stuff, just do this
NSFetchRequest *fetchRequest = [MessageLists fetchRequest];
NSError *error;
NSLog(@"All Records is %@",[context executeFetchRequest:fetchRequest error:&error]);
Upvotes: 1