美文网首页
Swift 的汉字排序 — 拼音、注音、笔画

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

作者: 麦志超 | 来源:发表于2023-09-21 10:47 被阅读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
    }
    

    相关文章

      网友评论

          本文标题:Swift 的汉字排序 — 拼音、注音、笔画

          本文链接:https://www.haomeiwen.com/subject/vbqzvdtx.html