NSPredicate
suggest changeSyntax
CONTAINSmatches a substring.
NSPredicate *filterByName = [NSPredicate predicateWithFormat:@"self.title CONTAINS[cd] %@",@"Tom"];
LIKEmatches a pattern.*and?are wildcards. With neither wildcard, it matches the whole string.[cd]makes the match case- and diacritic-insensitive.
NSPredicate *filterByNameCIS = [NSPredicate predicateWithFormat:@"self.title LIKE[cd] %@",@"Tom and Jerry"];
=matches equal values. Without[cd], the comparison is case-sensitive.
NSPredicate *filterByNameCS = [NSPredicate predicateWithFormat:@"self.title = %@",@"Tom and Jerry"];
INmatches values contained in a collection.
NSPredicate *filterByIds = [NSPredicate predicateWithFormat:@"self.id IN %@",@[@"7CDF6D22-8D36-49C2-84FE-E31EECCECB79", @"7CDF6D22-8D36-49C2-84FE-E31EECCECB76"]];
NOT (... IN ...)excludes values contained in a collection.
NSPredicate *filterByNotInIds = [NSPredicate predicateWithFormat:@"NOT (self.id IN %@)",@[@"7CDF6D22-8D36-49C2-84FE-E31EECCECB79", @"7CDF6D22-8D36-49C2-84FE-E31EECCECB76"]];
Remarks
For more details read NSPredicate in Apple documentation
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents