Created
December 16, 2017 09:06
-
-
Save amosavian/8f1f7f8add8e6552ce7557d7db231e4c to your computer and use it in GitHub Desktop.
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 String { | |
private func regionalIndicatorSymbol(unicodeScalar: UnicodeScalar) -> UnicodeScalar? { | |
let uppercaseA = UnicodeScalar("A")! | |
let regionalIndicatorSymbolA = UnicodeScalar("\u{1f1e6}")! | |
let distance = unicodeScalar.value - uppercaseA.value | |
return UnicodeScalar(regionalIndicatorSymbolA.value + distance) | |
} | |
public var emojiFlag: String { | |
return self.uppercased().unicodeScalars.map({ | |
String(regionalIndicatorSymbol(unicodeScalar: $0)!) | |
}).joined() | |
} | |
} | |
"IR".emojiFlag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment