1

In my swift project, I have to show the list of available Locale Identifiers. If user selects a locale like "ar" i.e. lanugage code alone. How I can get the currency symbols or number formats for this.

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)")
}
}

My question is explained in the code comment

0 Answers0