Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.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
从iOS中的语言代码获取货币代码/符号_Ios_Swift_Nslocale - Fatal编程技术网

从iOS中的语言代码获取货币代码/符号

从iOS中的语言代码获取货币代码/符号,ios,swift,nslocale,Ios,Swift,Nslocale,在我的swift项目中,我必须显示可用区域设置标识符的列表。如果用户选择类似“ar”的语言环境,即仅使用语言代码。如何获取货币符号或数字格式 func listCountriesAndCurrencies() { let localeIds = Locale.availableIdentifiers var countryCurrency = [String: String]() for localeId in localeIds { let locale = Locale(ident

在我的swift项目中,我必须显示可用区域设置标识符的列表。如果用户选择类似“ar”的语言环境,即仅使用语言代码。如何获取货币符号或数字格式

func listCountriesAndCurrencies() {

let localeIds = Locale.availableIdentifiers
var countryCurrency = [String: String]()
for localeId in localeIds {
    let locale = Locale(identifier: localeId)

    if let country = locale.regionCode, country.count == 2 { // how to get currency for locale without region code ?
        if let currency = locale.currencySymbol {
            countryCurrency[localeId] = currency
        }
    }
}

let sorted = countryCurrency.keys.sorted()
for country in sorted {
    let currency = countryCurrency[country]!

    print("country: \(country), currency: \(currency)")
}
}
我的问题在代码注释中解释