I have been working with a Core Data database and it is set to load some data out of the database using the following code:
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AssignmentsInfo" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *dataReturn = [context executeFetchRequest:fetchRequest error:&error];
dataSet = dataReturn;
NSFetchRequest *fetchRequestSubjects = [[NSFetchRequest alloc]init];
NSEntityDescription *entitySubjects = [NSEntityDescription entityForName:@"Subjects" inManagedObjectContext:context];
[fetchRequestSubjects setEntity:entitySubjects];
NSError *errorSubjects;
NSArray *subjectList = [context executeFetchRequest:fetchRequestSubjects error:&errorSubjects];
But running this code returns the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
* First throw call stack:
(0x16b1022 0x1842cd6 0xed3871 0x599a 0xe3a1e 0xe2fec 0x109f1d 0xf41cb 0x10adf1 0x10ae0d 0x10aea9 0x496f5 0x4973c 0x1a596 0x1b274 0x2a183 0x2ac38 0x1e634 0x159bef5 0x1685195 0x15e9ff2 0x15e88da 0x15e7d84 0x15e7c9b 0x1ac65 0x1c626 0x32ed 0x2385 0x1)
terminate called throwing an exception(lldb)
I am not quite sure why this error is happening. I have triple checked and there are NO typos in the xcode model I have. The managedObjectContext is also perfectly working. Thanks for the help
Try:
1. Debug and see if
entitySubjectsis notnil2. Try Product->Clean, Product->Build then try running, if it doesn’t help
3. If you have added a new model version, you may have forgotten to set it as “Current Version” and if that’s not the case
4. Your data may have got corrupted, try deleting it and run again
5. Last try is to recreate your model again, something might have gone wrong…