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

时间:2017-11-07 11:41:25

标签: ios swift nslocale

在我的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)")
}
}

我的问题在代码注释中解释

0 个答案:

没有答案