我一直在使用 Core Data 数据库,它设置为使用以下代码从数据库中加载一些数据:
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];
但是运行此代码会返回错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
*第一掷调用堆栈:(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)终止叫做抛出异常(LLDB)
我不太确定为什么会发生此错误。我进行了三次检查,并且我拥有的 xcode 模型中没有拼写错误。managedObjectContext 也可以正常工作。谢谢您的帮助