What are the pros and cons for using a single NSPredicate with a value like “Condition1 AND condition2” vs. using a NSCompoundPredicate with two subpredicates?
Even if I construct it dynamically, the first option seems much more compact to code.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ve almost answered your own question – it’s more a cleanliness of code question than a performance question!
NSCompoundPredicateis more useful if you are creating lots of conditions in seperate parts of your code that you then want to combine.If your predicate is being created all in one place, just use ‘ AND ‘ in a format string.
It’s really up to you when you decide that your predicate is complicated enough that creating it needs to be split into separate methods.
i.e.
If it’s just
a AND bthen use a single predicateIf it’s
a AND (b OR c OR c) AND (e OR b)then use compound predicates!