Reputation: 1064
I want to sort my table view data based on pinyin of Chinese characters. How would I do this ? I did sort it but when it sorts it just divide all sections into characters what I want is when it sorts into sections it take pinyin and sort it with alphabetical order not with characters. And I can also use section Index ABCDEF....XYZ# to go to different sections. Right now it starts adding characters both in section and section index.
Upvotes: 1
Views: 930
Reputation: 8855
CoreFoundation provides transform method to convert from Chinese to PinYin:
import CoreFoundation
func stringPinYin(src: String) -> String {
let stringRef = NSMutableString(string: src) as CFMutableString
CFStringTransform(stringRef, nil, kCFStringTransformToLatin, false)
CFStringTransform(stringRef, nil, kCFStringTransformStripDiacritics, false)
return stringRef as String
}
中文
-> zhong wen
Upvotes: 2