按属性 IN 数组过滤核心数据结果
目前,我的 Core Data 已成功返回标题为 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 值。
如何让我的核心数据请求仅返回 tid 属性与 filterArray
中的值之一匹配的事件?我相信答案与 NSPredicate 有关,但我对它还不够熟悉,还不能让它屈服于我的意愿。
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];
One property of the Event entity is a string titled tid
. I also have an array filterArray
that contains all allowed tid values.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
看看 中的聚合操作 href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-SW1" rel="noreferrer">谓词编程指南。
编辑
看看NSPredicate iPhone 3.2 SDK 核心数据“IN 子句”NSInvalidArgumentException 异常。这和你有同样的错误。问题是列/属性名称中的拼写错误。语法应该没问题,不能只找到
tid
。Try this:
Have a look at the Aggregate Operations in the Predicate Programming Guide.
EDIT
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
.