Created
January 8, 2022 13:00
-
-
Save Ceri-anne/605aba777dc38a60393c6970591845cb to your computer and use it in GitHub Desktop.
Flag emoji from country code
This file contains 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
import Foundation | |
func flagEmoji(for countryCode: String) -> String? { | |
guard Locale.isoRegionCodes.contains(countryCode) else { return nil } | |
return countryCode | |
.uppercased() | |
.unicodeScalars | |
.map { 127397 + $0.value } | |
.compactMap { UnicodeScalar($0) } | |
.map { String($0) } | |
.joined() | |
} | |
let emoji = flagEmoji(for: "GB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment