从iOS中的语言代码获取货币代码/符号
在我的swift项目中,我必须显示可用区域设置标识符的列表。如果用户选择类似“ar”的语言环境,即仅使用语言代码。如何获取货币符号或数字格式从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
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)")
}
}
我的问题在代码注释中解释