In my current implementation of a UISearchBarController
I'm using [NSString compare:]
inside the filterContentForSearchText:scope:
delegate method to return relevant objects based on their name property to the results UITableView
as you start typing.
So far this works great in English and Korean, but what I'd like to be able to do is search within NSString
's defined character clusters. This is only applicable for a handfull of languages, of which Korean is one.
In English, compare:
returns new results after every letter you enter, but in Korean the results are generated once you complete a recognized grapheme cluster. I would like to be able to search through my Korean objects name property via the individual elements that make up a syllable.
Can anyone shed any light on how to approach this? I'm sure it has something to do with searching through UTF16 characters manually, or by utilising a lower level class.
Cheers!
Here is a specific example that's just not working:
`NSString *string1 = @"이";
`NSString *string2 = @"ㅣ";
NSRange resultRange = [[string1 decomposedStringWithCanonicalMapping] rangeOfString: [string2 decomposedStringWithCanonicalMapping] options:(NSLiteralSearch)];
The result is always NSNotFound, with or without decomposedStringWithCanonicalMapping
.
Any ideas?