How to get ISOCurrencyCode from a ISOCountryCode i

2019-02-05 01:47发布

I have the ISOCountryCode avaliable and now i want to derive the currencyCode of this country from the ISOCountryCode. How can i achieve that?

  NSString *countryCode =  < get from someother view>;     
  NSString *currencyCode = ?;

I receive this country code from some other view on runtime?

2条回答
2楼-- · 2019-02-05 02:23

You will need to use NSLocale. To retrieve the currency code from a specific country code:

NSString *countryCode = @"US";

NSDictionary *components = [NSDictionary dictionaryWithObject:countryCode forKey:NSLocaleCountryCode];
NSString *localeIdent = [NSLocale localeIdentifierFromComponents:components]; 
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:localeIdent] autorelease];
NSString *currencyCode = [locale objectForKey: NSLocaleCurrencyCode];

You can also get it for the current locale, ie the user settings:

NSString *currencyCode = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencyCode];
查看更多
该账号已被封号
3楼-- · 2019-02-05 02:27

NSLocale encapsulates a rich set of domain-specific information, among others you have NSLocaleCurrencyCode:

 if let code = NSLocale.currentLocale().objectForKey(NSLocaleCurrencyCode) {
                print("\(code)")
            }
查看更多
登录 后发表回答