I have found the answer for this for objective-c but Im having a hard time doing this in swift.
I have used this to get the country code for the current location:
let countryCode = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String
print(countryCode)
// printing for example US
But how do I convert this country code to a country name, like in this example converting "US" to "United States"?
A super clean Swift 3 version would be:
You can change the locale identifier to eg. Locale.current.identifier if you want localized names. The example above is for English only.
Swift 3
Note: If you manually entered
localIdentifier
means iOS 8 not listed all country name (Eg: "en_US")Working on Swift3
Use in app delegate
Try doing something like this:
with this helper function that I found here:
I figured this out by researching into this related question.
Swift 3
Swift 4