Swift 的汉字排序 — 拼音、注音、笔画

2023-09-21  本文已影响0人  麦志超

拼音排序

let locale = Locale(identifier: "zh@collation=pinyin")

let pinyinSorted = nameList.sorted {
    $0.compare($1, locale: locale) == .orderedAscending
}

注音排序

let localeZhuyin = Locale(identifier: "zh@collation=zhuyin")

let zhuyinSorted = nameList.sorted {
    $0.compare($1, locale: localeZhuyin) == .orderedAscending
}

笔画排序

let localeStroke = Locale(identifier: "zh@collation=stroke")

let strokeSorted = nameList.sorted {
    $0.compare($1, locale: localeStroke) == .orderedAscending
}
上一篇下一篇

猜你喜欢

热点阅读