8

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?

awsome
  • 2,143
  • 2
  • 23
  • 41

2 Answers2

15

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];
ksoderstrom
  • 489
  • 3
  • 5
  • My problem is like this. A user chooses a country from a list. And for this country I need to find the currency. And both the ways you have specified does not fulfill my requirement. I cannot hardcode anything. I have edited my question also a little bit. I hope that you understood my question. – awsome Aug 08 '10 at 11:11
0

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

 if let code = NSLocale.currentLocale().objectForKey(NSLocaleCurrencyCode) {
                print("\(code)")
            }