2010-08-08 32 views

回答

14

您将需要使用NSLocale。从一个特定的国家代码获取货币代码:

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]; 

你也可以把它当前区域,即用户设置:

NSString *currencyCode = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencyCode]; 
+0

我的问题是这样的。用户从列表中选择一个国家。而对于这个国家,我需要找到货币。而你指定的两种方式都不符合我的要求。我无法硬编码任何东西。我也编了一点我的问题。我希望你能理解我的问题。 – awsome 2010-08-08 11:11:28

+0

啊,我明白了。我已经更新了我的答案,如何做到这一点。 – ksoderstrom 2010-08-08 11:35:52

+0

谢谢...这就是我一直在寻找... – awsome 2010-08-08 21:00:46

0

NSLocale封装了一组丰富的特定领域的信息,其中包括NSLocaleCurrencyCode:

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