Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate of special characters - iPhone

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

like image 879
ncohen Avatar asked Mar 19 '10 03:03

ncohen


People also ask

What does NSPredicate do?

A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.

What is NSPredicate format in Swift?

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.


1 Answers

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.

like image 91
Todd Yandell Avatar answered Sep 17 '22 23:09

Todd Yandell