Hey so I'm using a NSPredicate to filter an array. Currently I use the following piece of code:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@", searchText];
This has been working alright as it looks for the attribute .name and checks to see if it is contained in the searchText. I was wondering if there is a way for me to change it from checking if it's contained in the search text to if the search text begins with the search filter. I.E. if the search text is school
and I type sc
as the filter the search text stays but if I type sco
the search text school
is filtered out. Is there some sort of beginswith
that I can use instead of contains[c]
. Thanks!
Yes, exactly that in fact:
BEGINSWITH
The left-hand expression begins with the right-hand expression.CONTAINS
The left-hand expression contains the right-hand expression.ENDSWITH
The left-hand expression ends with the right-hand expression.LIKE
The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters, where ? matches 1 character and * matches 0 or more characters.MATCHES
The left hand expression equals the right hand expression using a regex-style comparison according to ICU v3 (for more details see the ICU User Guide for Regular Expressions).