How to perform a case and diacritic insensitive filter of an array of NSDictionaries (not NSString)?
I have an array of dictionaries. I would like to filter that array by seeing if the @"name" field of each dictionary contains a given string.
The catch is that I would like to make my filtering insensitive to case and diacritics.
If the array contained only strings I could easily use an NSPredicate. However, it doesn't, and I don't see a way that NSPredicate can accomodate this situation.
If I only开发者_Go百科 cared about case-insensitivity, I could loop through all the items and compare the lowercased filter string to the lowercased name. But I don't know of a similar trick for diacritics.
Is there a good solution to this somewhere?
Check the top answer on this question:
Non US characters in section headers for a UITableView
You should be able to use that code to get rid of the diacritics and then do a case insensitive compare or search.
What about something like:
NSArray * array = .....
NSString * searchString = @"foo";
NSArray * filteredArray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name contains[cd] %@", searchString]];
精彩评论