Skip to content

Instantly share code, notes, and snippets.

@elmodos
Created November 6, 2022 18:06
Show Gist options
  • Save elmodos/d82dfa6b2d1fdf6eac0d7d5c7c9b6675 to your computer and use it in GitHub Desktop.
Save elmodos/d82dfa6b2d1fdf6eac0d7d5c7c9b6675 to your computer and use it in GitHub Desktop.
Locale to country flag emoji
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