Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 234
Yanhua Avatar asked Nov 01 '10 16:11

Yanhua


2 Answers

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

Pass in NSLocaleCurrencyCode in key and your currency code in value

like image 50
Claus Broch Avatar answered Nov 01 '22 17:11

Claus Broch


// 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

like image 5
CocoaBob Avatar answered Nov 01 '22 15:11

CocoaBob