Is there a shorter way to write the format string for a predicate equivalent to this:
[NSPredicate predicateWithFormat: @"key1 CONTAINS[cd] %@ OR key2 CONTAINS[cd] %@ OR key3 CONTAINS[cd] %@", searchString, searchString, searchString];
I have written a few predicate format strings like this, and I was thinking to simplify that by writing a method that takes an array of key paths and the search string to construct such a predicate. But I thought I’d ask if there is a built-in way to do this, before doing that.
NSCompoundPredicateis a subclass ofNSPredicateand takes anNSArrayofNSPredicateinstances. However, this would mean that you still have to construct theNSPredicateobjects (the subpredicates if you will) yourself. My suggestion is to write your own method (as you are planning to) but useNSCompoundPredicateas it is designed for this purpose.