iphoneobjective-ccore-dataspecial-charactersnspredicate

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


Solution

  • 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.