I'm trying to make a predicate that includes special characters
For example:
[[myIngredients filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"name BEGINSWITH[c] %@", [alphabet objectAtIndex:idx]]];
Here I will get all the ingredient which starts with (let say for idx = 5) 'e'. As I have to do my app in english and french, some ingredients start with special character like 'é' or even 'œ' for 'o'. How can I include these special characters in my predicate?
Best
A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.
NSPredicate is a Foundation class that specifies how data should be fetched or filtered. Its query language, which is like a cross between a SQL WHERE clause and a regular expression, provides an expressive, natural language interface to define logical conditions on which a collection is searched.
I think you might be looking for the “diacritic insensitive” flag that NSPredicate supports. It’s just like the “c” flag you’re already using, except you use a “d”. Like so:
… predicateWithFormat:@"name BEGINSWITH[cd] %@", …
Now the string “e” will also match “é”, “ê”, “ë”, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With