I’m trying to search multiple fields. Something like this:
[NSPredicate predicateWithFormat:@"(name title contains[cd] %@) AND (title contains[cd] %@", self.searchBar.text];
A search is made on both the name field or the title field.
Also, if anyone knows what a wildcard search would look like I’d appreciate that too.
I tried:
[NSPredicate predicateWithFormat:@"* contains[cd] %@", self.searchBar.text];
my error code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(name contains[cd] %@) OR (title contains[cd] %@"'
First off, you must specify all the properties to examine, since there is no fixed or universal list of properties, and in Objective-C there is no real semantic distinction between a property and any other method.
Second off, to examine multiple properties to see if they contain a search string, you should use
OR, notAND, since your search is satisfied if any of the properties match, not all.Otherwise, the syntax you have appears correct (I’m assuming
name titlein the first subpredicate is meant to be justname.)