如何从iphone sdk中的ISOCountryCode获取ISOCurrencyCode?

aws*_*ome 8 iphone objective-c iphone-sdk-3.0

我有ISOCountryCode可用,现在我想从ISOCountryCode派生这个国家的currencyCode.我怎样才能实现这一目标?

  NSString *countryCode =  < get from someother view>;     
  NSString *currencyCode = ?;
Run Code Online (Sandbox Code Playgroud)

我从运行时的其他视图中收到此国家/地区代码?

kso*_*rom 15

您将需要使用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];
Run Code Online (Sandbox Code Playgroud)

您还可以获取当前区域设置,即用户设置:

NSString *currencyCode = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencyCode];
Run Code Online (Sandbox Code Playgroud)