gpt4 book ai didi

objective-c - 核心数据 : Keypath Error Not Found in Entity

转载 作者:太空狗 更新时间:2023-10-30 03:17:56 26 4
gpt4 key购买 nike

有人能告诉我这段代码有什么问题吗?它会引发以下错误并导致应用程序崩溃:

reason: 'keypath Studies.patients.PatientName not found in entity <NSSQLEntity Studies id=3>'

代码:

 - (void)viewDidLoad {
[super viewDidLoad];

test_coredataAppDelegate *appDelegate = (test_coredataAppDelegate *)[[UIApplication sharedApplication] delegate];
self.context = appDelegate.managedObjectContext;


NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Studies" inManagedObjectContext:_context];
[fetchRequest setEntity:entity];
/**/
NSLog(patientName);
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:
@"(Studies.patients.PatientName == %@ )",patientName]];



NSError *error;
self.StudiessList = [_context executeFetchRequest:fetchRequest error:&error];
self.title = @"patients";
[fetchRequest release];

}

最佳答案

首先,由于您的提取实体是 Studies,因此您不会将其包含在谓词中,因为 Studies 对象是首先接受谓词测试的对象。所以你的谓词至少应该是:

patients.PatientName == %@

但是,按照惯例,patients 表示一对多关系。如果是这样,则意味着 patients 的实际值是一组(大概)Patient 对象。因此,您不能像上面那样向集合请求属性值:相反,您必须请求集合中与谓词匹配的所有对象的新集合。像这样使用 ANY 或 All 运算符:

ALL patients.PatientName == %@

我要补充一点,按照惯例,所有属性和关系名称都以小写字母开头,因此如果 PatientName 是一个属性,它应该是 patientName

关于objective-c - 核心数据 : Keypath Error Not Found in Entity <NSSQLEntity Studies id=3>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5182969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com