-
-
Save mumer92/618bc4e4316c9e2f7de6eb0e048db3a5 to your computer and use it in GitHub Desktop.
Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
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
extension Locale { | |
/// Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc. | |
func currencySFSymbol(filled: Bool, withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage { | |
// Default currency symbol will be the Animal Crossing Leaf coin to remain impartial to any specific country | |
let defaultSymbol = UIImage(systemName: "leaf.circle\(filled ? ".fill" : "")")! | |
guard let currencySymbolName = currencySymbolNameForSFSymbols() else { return defaultSymbol } | |
let systemName = "\(currencySymbolName).circle\(filled ? ".fill" : "")" | |
return UIImage(systemName: systemName, withConfiguration: configuration) ?? defaultSymbol | |
} | |
private func currencySymbolNameForSFSymbols() -> String? { | |
guard let currencySymbol = currencySymbol else { return nil } | |
let symbols: [String: String] = [ | |
"$": "dollar", | |
"¢": "cent", | |
"¥": "yen", | |
"£": "sterling", | |
"₣": "franc", | |
"ƒ": "florin", | |
"₺": "turkishlira", | |
"₽": "ruble", | |
"€": "euro", | |
"₫": "dong", | |
"₹": "indianrupee", | |
"₸": "tenge", | |
"₧": "peseta", | |
"₱": "peso", | |
"₭": "kip", | |
"₩": "won", | |
"₤": "lira", | |
"₳": "austral", | |
"₴": "hryvnia", | |
"₦": "naira", | |
"₲": "guarani", | |
"₡": "coloncurrency", | |
"₵": "cedi", | |
"₢": "cruzeiro", | |
"₮": "tugrik", | |
"₥": "mill", | |
"₪": "shekel", | |
"₼": "manat", | |
"₨": "rupee", | |
"฿": "baht", | |
"₾": "lari", | |
"R$":" brazilianreal" | |
] | |
guard let currencySymbolName = symbols[currencySymbol] else { return nil } | |
return "\(currencySymbolName)sign" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment