Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从iphone sdk中的IsocurryCode获取IsocurryCode?_Iphone_Objective C_Iphone Sdk 3.0 - Fatal编程技术网

如何从iphone sdk中的IsocurryCode获取IsocurryCode?

如何从iphone sdk中的IsocurryCode获取IsocurryCode?,iphone,objective-c,iphone-sdk-3.0,Iphone,Objective C,Iphone Sdk 3.0,我有可用的等CountryCode,现在我想从等CountryCode推导出这个国家的货币代码。我怎样才能做到这一点 NSString *countryCode = < get from someother view>; NSString *currencyCode = ?; NSString*countryCode=; NSString*currencyCode=?; 我在运行时从其他视图收到此国家代码?您需要使用NSLocale。要从特定国家/地区代码检索

我有可用的等CountryCode,现在我想从等CountryCode推导出这个国家的货币代码。我怎样才能做到这一点

  NSString *countryCode =  < get from someother view>;     
  NSString *currencyCode = ?;
NSString*countryCode=;
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)")
            }

我的问题是这样的。用户从列表中选择一个国家。对于这个国家,我需要找到货币。你指定的两种方式都不符合我的要求。我不能硬编码任何东西。我对我的问题也做了一些修改。我希望你能理解我的问题。