我可以对NSFetchRequest应用多个谓词吗?最好手动解析我的结果吗? [英] Can I apply multiple predicates to an NSFetchRequest? Would it be better to manually parse my results?
问题描述
Ok我有一个基本的iPad应用程序要求用户的5个搜索/过滤条件。基于这些数据,我需要转到我的核心数据db,并拉出符合该标准的任何受管对象。似乎我需要应用多个谓词到同一个请求,是可能吗?或者我可以写一个真正长的花哨谓词?有多种要求?我应该如何处理?
Ok I have a basic iPad app that asks for 5 search/filter criteria from the user. Based on this data, I need to go to my core data db, and pull out any managed objects that fit that criteria. It seems like I need to apply more than one predicate to the same request, is that possible? Or could I just write a really long fancy predicate? With multiple requirements? How should I approach that?
这是一个好主意,通过抓取请求抓住所有实体,然后循环遍历每个数组,并抓住任何对象,我发现符合我的搜索条件?
Would it be a good idea to just grab all the entities through the fetch request, and then loop through each array and grab any objects that I find that fit my search criteria?
请指教!
推荐答案
您正在寻找复合谓词,这里有一个AND谓词的示例:
Yes it's possible. You're looking for compound predicates and here's an example with AND predicates:
NSPredicate *compoundPredicate
= [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray of Predicates]];
您也可以使用 notPredicateWithSubpredicates
和<$
这篇关于我可以对NSFetchRequest应用多个谓词吗?最好手动解析我的结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!