NSPredicate with Multiple Conditions

Brandon

I am trying to create a NSPredicate with multiple conditions. I've found several solutions, but none of them appear to be working with my method. The best looking one I've found is below.

This is my single predicate method, and it works just fine:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", 
searchText];
filteredBusinesses = [businesses filteredArrayUsingPredicate:predicate];

Here is my edited version with multiple conditions. I'm not sure whats going wrong. Any ideas?

NSPredicate *p1 = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
NSPredicate *p2 = [NSPredicate predicateWithFormat:@"businessArea contains[c] %@", 
searchText];

NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1, p2]];
filteredBusinesses = [businesses filteredArrayUsingPredicate:predicate];
Nikunj Agola

You can try this

NSPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[p1, p2]];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章