Sam
Sam

Reputation: 598

Accent insensitive string comparison?

Is there any way to do an accent insensitive string comparison? For example, é == e? I couldn't find any options to pass rangeOfString:options:. Any help is greatly appreciated.

Upvotes: 16

Views: 3431

Answers (2)

gklka
gklka

Reputation: 2574

If you also want a substring search and have an array of items you want to filter I recommend this:

[self.objects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id  _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
    MyClass *object = (MyClass *)evaluatedObject;
    if ([object.name localizedStandardContainsString:filterString]) return YES;
    return NO;
}]];

Upvotes: 0

Mike Weller
Mike Weller

Reputation: 45598

You want to pass the NSDiacriticInsensitiveSearch option to whichever method you use (e.g. compare:options: or rangeOfString:options:)

Upvotes: 27

Related Questions