0

My scenario, I am trying to get country code by using country name. I tried below code but Its only getting country name.

func countryName(from countryCode: String) -> String {
    if let name = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: countryCode) {
        // Country name was found
        return name
    } else {
        // Country name cannot be found
        return countryCode
    }
}
jackios
  • 155
  • 2
  • 11

1 Answers1

-2
if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
   return countryCode
}
nimesh surani
  • 177
  • 1
  • 13