Created
November 6, 2022 18:06
-
-
Save elmodos/d82dfa6b2d1fdf6eac0d7d5c7c9b6675 to your computer and use it in GitHub Desktop.
Locale to country flag emoji
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 flagEmoji: String? { | |
let base: UInt32 = 127397 | |
return countryCode? | |
.unicodeScalars | |
.compactMap { Unicode.Scalar(base + $0.value) } | |
.reduce("", { $0.appending(String($1)) } ) | |
} | |
} | |
// (lldb) print Locale(identifier: "uk_UA").flagEmoji | |
// (String?) $R3 = "🇺🇦" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment