Last active
November 14, 2019 07:17
-
-
Save yycking/b09c7c4dbcae2ba4a6b9e642a9c7f5e3 to your computer and use it in GitHub Desktop.
convert country code to emoji flag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Locale { | |
var flagCode: String { | |
guard let country = self.regionCode else {return "🌐"} | |
let base : UInt32 = 127397 | |
let code = country.unicodeScalars.compactMap{UnicodeScalar(base + $0.value)} | |
return String(String.UnicodeScalarView(code)) | |
} | |
} | |
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Text(Locale.current.flagCode) | |
.font(.system(size: 60)) | |
} | |
} | |
import PlaygroundSupport | |
PlaygroundPage.current.setLiveView(ContentView()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment