Swift turn a country code into a emoji flag via unicode

后端 未结 7 844
日久生厌
日久生厌 2020-12-07 14:08

I\'m looking for a quick way to turn something like:

let germany = \"DE\" 

into

let flag = \"\\u{1f1e9}\\u{1f1ea}\"
         


        
相关标签:
7条回答
  • 2020-12-07 14:32

    Another function for turning a two-letter country code into its emoji flag using Swift 5.

    internal func getFlag(from countryCode: String) -> String {
    
        return countryCode
            .unicodeScalars
            .map({ 127397 + $0.value })
            .compactMap(UnicodeScalar.init)
            .map(String.init)
            .joined()
    }
    
    0 讨论(0)
提交回复
热议问题