I am using a UILocalizedIndexedCollation
to get the array of local sectionIndexTitles
.
Now I want to check a string if it starts with some element from these sectionIndexTitles.
Assuming my language is Korean, sectionIndexTitles
are this:
"ㄱ,ㄴ,ㄷ,ㄹ,ㅁ,ㅂ,ㅅ,ㅇ,ㅈ,ㅊ,ㅋ,ㅌ,ㅍ,ㅎ,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,#"
Question
How do I check if the String "나비" starts with "ㄴ"?
The problem is that the first "character" is "나" and "ㄴ" never stands by itself in a character. So it seems like the sectionIndexTitles
should actually contain first character-combinations as e.g. 나
.
"ㄴ".characters.first // "ㄴ"
"나비".characters.first // "나"
"나비".hasPrefix("ㄴ") // false
"나비".localizedStandardRange(of: "ㄴ") // nil
Update, following up on your comment:
"나비".range(of: "ㄴ") // nil
Update 2: Question
How can I create alphabetic section headers like "A", "B", "C", ... and put in localized string elements like "나비"?
In e.g. Korean there are various combinations for the first "character", so the
sectionIndexTitles
from UILocalizedIndexedCollation
(e.g. "ㄴ") can't be used to sort elements into the right section