NSPredicate omits special characters like á â á in filterContentForSearchText method

StackOverflow https://stackoverflow.com/questions/23418282

  •  13-07-2023
  •  | 
  •  

Domanda

I am developing an app with an UISearchBar and I need to filter some names with special characters like à, è, ê and so on.. but if I don't type the correct string with the special character it doesn't appear.

Ex: If I am looking for cómodo word I can't find this word if I don't type exactly

How could I get that word without type that special characters? for example typing just co.

This is my NSPredicate:

 NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"SELF.word BEGINSWITH[c] %@",
                                    searchText];

Thank you

È stato utile?

Soluzione

Ignore diacrtical needs to be specified, "[cd]" instead of "[c]".

See NSHipster: NSPredicate.

NSComparisonPredicate Options:
NSDiacriticInsensitivePredicateOption: A diacritic-insensitive predicate. You represent this option in a predicate format string using a [d] following a string operation (for example, "naïve" like[d] "naive").

Such a common error, it kept me from finding my Metro Station in Paris.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top