我有ISOCountryCode可用,现在我想从ISOCountryCode派生这个国家的currencyCode。我怎么能做到这一点?如何从iphone sdk中的ISOCountryCode获取ISOCurrencyCode?
NSString *countryCode = < get from someother view>;
NSString *currencyCode = ?;
我从运行时的其他视图中收到此国家/地区代码?
我有ISOCountryCode可用,现在我想从ISOCountryCode派生这个国家的currencyCode。我怎么能做到这一点?如何从iphone sdk中的ISOCountryCode获取ISOCurrencyCode?
NSString *countryCode = < get from someother view>;
NSString *currencyCode = ?;
我从运行时的其他视图中收到此国家/地区代码?
您将需要使用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];
NSLocale封装了一组丰富的特定领域的信息,其中包括NSLocaleCurrencyCode:
if let code = NSLocale.currentLocale().objectForKey(NSLocaleCurrencyCode) {
print("\(code)")
}
我的问题是这样的。用户从列表中选择一个国家。而对于这个国家,我需要找到货币。而你指定的两种方式都不符合我的要求。我无法硬编码任何东西。我也编了一点我的问题。我希望你能理解我的问题。 – awsome 2010-08-08 11:11:28
啊,我明白了。我已经更新了我的答案,如何做到这一点。 – ksoderstrom 2010-08-08 11:35:52
谢谢...这就是我一直在寻找... – awsome 2010-08-08 21:00:46