Skip to content

Instantly share code, notes, and snippets.

@hishma
Last active March 1, 2019 22:10
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 hishma/0058cb3937f7e55cc21dc677361da091 to your computer and use it in GitHub Desktop.
Save hishma/0058cb3937f7e55cc21dc677361da091 to your computer and use it in GitHub Desktop.
extension Locale {
/// An emoji representation of the locale's region.
var emoji: String? {
return regionalIndicatorSymbol
}
/// The regional indicator symbols are a set of 26 alphabetic Unicode characters (A–Z) intended to be used to encode
/// ISO 3166-1 alpha-2 two-letter country codes in a way that allows optional special treatment.
///
/// These were defined as part of the Unicode 6.0 support for emoji, as an alternative to encoding separate characters for each
/// country flag. Although they can be displayed as Roman letters, it is intended that implementations may choose to display them
/// in other ways, such as by using national flags. The Unicode FAQ indicates that this mechanism should be used and that
/// symbols for national flags will not be directly encoded.
///
/// See: https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
var regionalIndicatorSymbol: String? {
guard let regionCode = self.regionCode else { return nil }
let base: UInt32 = 127397
return regionCode.unicodeScalars.compactMap { String.init(UnicodeScalar(base + $0.value)!) }.joined()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment