NSPredicate vs NSCompoundPredicate?

What are the pros and cons of using a single NSPredicate with a value of type Condition1 AND condition2 versus using an NSCompoundPredicate with two sub-presentations?

Even if I build it dynamically, the first option seems more compact for the code.

+4
source share
1 answer

You almost answered your question - it's more about code cleanliness than a performance question!

NSCompoundPredicate more useful if you create many conditions in separate parts of your code that you want to combine.

If your predicate is created all in one place, just use "AND" in the format string.

It really depends on you when you decide that your predicate is complex enough to be divided into separate methods.

i.e.

If it's just a AND b , then use one predicate

If it is a AND (b OR c OR c) AND (e OR b) , then use compound predicates!

+11
source

All Articles