问题描述
我目前有Core Data成功返回标题为 Event
的特定实体的所有结果:
I currently have Core Data successfully returning all of the results for a specific entity titled Event
:
NSManagedObjectContext *context = [delegate managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Event"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
NSError *error;
NSArray *fetchResults = [context executeFetchRequest:request error:&error];
Event实体的一个属性是标题为 tid
。我也有一个数组 filterArray
包含所有允许的tid值。
One property of the Event entity is a string titled tid
. I also have an array filterArray
that contains all allowed tid values.
如何获取我的Core Data请求只返回具有与 filterArray
中的值之一匹配的tid属性的事件?我相信答案与NSPredicate有关,但是我还不够熟悉它,它不能让它弯曲我的意志。
How can I get my Core Data request to only return events that have a tid property that matches one of the values in filterArray
? I believe the answer relates to NSPredicate but I am not familiar enough with it yet to get it to bend to my will.
推荐答案
尝试此操作:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"tid IN %@", filterArray];
[request setPredicate:predicate];
请查看中的。
编辑
请查看。这是同样的错误,你有。问题是列/属性名称中有一个拼写错误。语法应该没问题,它不能只找到 tid
。
Have a look at NSPredicate iPhone 3.2 SDK Core Data "IN clause" NSInvalidArgumentException exception. It's same error you have. The problem was a typo in the column/attribute name. The syntax should be alright, it can't just find tid
.
这篇关于按属性IN数组过滤Core数据结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!