I want to display Currency Symbol based on Country name or country code using NSLocale I have all the country name list. suppose I have selected USA then it
You can Get currency code from Country name, tested it on swift3, first of all add this extension
extension NSLocale {
class func locales1(countryName1 : String) -> String {
let locales : String = ""
for localeCode in NSLocale.isoCountryCodes {
let countryName = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: localeCode)
if countryName1.lowercased() == countryName?.lowercased() {
return localeCode
}
}
return locales
}
}
You will get the currency code from here
let countryCode = NSLocale.locales1(countryName1: "\(place.name)")
let countryCodeCA = countryCode
let localeIdCA = NSLocale.localeIdentifier(fromComponents: [ NSLocale.Key.countryCode.rawValue : countryCodeCA])
let localeCA = NSLocale(localeIdentifier: localeIdCA)
let currencySymbolCA = localeCA.object(forKey: NSLocale.Key.currencySymbol)
let currencyCodeCA = localeCA.object(forKey: NSLocale.Key.currencyCode)
print("\(currencyCodeCA!)")
self.currencyKey = currencyCodeCA! as! String