Skip to content

Instantly share code, notes, and snippets.

@Ceri-anne
Created January 8, 2022 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ceri-anne/605aba777dc38a60393c6970591845cb to your computer and use it in GitHub Desktop.
Save Ceri-anne/605aba777dc38a60393c6970591845cb to your computer and use it in GitHub Desktop.
Flag emoji from country code
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