Building a NSPredicate for a filter

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-15T07:50:45Z Indexed on 2010/04/15 7:53 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

Hi,

Just wondering what the best way to build a NSPredicate is if some filters are optional?

This is basically for a filter, so if some options aren't selected I don't to filter by them

eg. If I have option1 and option2 set for the filter.

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"option1 = %@ AND option2 = %@] ....

otherwise if just option1 NSPredicate* predicate = [NSPredicate predicateWithFormat:@"option1 = %@] ....

The key being there are 10 different options to filter, so I don't want to have to code for the 10x10 possible combinations.

Thanks

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa