I want to show both currency codes and its display name in a table view in order to let users select, e.g.
CHF-Swiss Franc
EUR-Euro
RUB-Russion Rubble
I know I can use [NSLocale ISOCurrencyCodes] to get all currency codes, but how can I get the currency display name (Swiss Franc, Euro, etc...) of the currency code? and I hope the dispaly name support localization. Thanks.
You can use NSLocale's -(NSString *)displayNameForKey:(id)key value:(id)value
Pass in NSLocaleCurrencyCode
in key
and your currency code in value
// Get currency code of Canada
var countryCodeCA = "ca"
let localeIdCA = NSLocale.localeIdentifierFromComponents([NSLocaleCountryCode:countryCodeCA])
let localeCA = NSLocale(localeIdentifier: localeIdCA)
let currencySymbolCA = localeCA.objectForKey(NSLocaleCurrencySymbol)
let currencyCodeCA = localeCA.objectForKey(NSLocaleCurrencyCode)
// Display it in Chinese
let localeIdCN = NSLocale.localeIdentifierFromComponents([NSLocaleLanguageCode:"zh_cn"])
let localeCN = NSLocale(localeIdentifier: localeIdCN)
localeCN.displayNameForKey(NSLocaleCurrencyCode, value: currencyCodeCA!)
// Display it in the system language
let localeCurr = NSLocale.systemLocale()
localeCurr.displayNameForKey(NSLocaleCurrencyCode, value: currencyCodeCA!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With