How to get both a currency code and a localized display name in iOS?

I want to show both currency codes and its display name in a table so that users can choose, for example

CHF-Swiss Franc

EUR-Euro

RUB-Russion Rubble

I know that I can use [NSLocale ISOCurrencyCodes] to get all currency codes, but how can I get the display name of the currency (Swiss franc, euro, etc.) of the currency code? and I hope the dispatcher name supports localization. Thank.

+5
source share
2 answers

You can use NSLocale -(NSString *)displayNameForKey:(id)key value:(id)value

Go in NSLocaleCurrencyCodeto keyand your currency codevalue

+11
source
// 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!)

enter image description here

+4

All Articles