NSPredicate omits special characters like á â á in filterContentForSearchText method

你。 提交于 2019-12-31 04:06:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/23418282/nspredicate-omits-special-characters-like-%c3%a1-%c3%a2-%c3%a1-in-filtercontentforsearchtext-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!