Im retrieving a country name from a server in english. For example, "Spain"
What I want to do is, assuming the country name is going to be written in english, get the country code.
What should I do? I´ve found getting the country name from the country code quite easy, but I´ve got no idea of how to do the opposite operation.
Thanks a lot.
My compact version including the fix for matching only against english country names version.
So this solution works well in swift 4 taken from comments above...
enjoy!
Swift 3.0 :
Getting the country code and country name as NS Dictionary-
This is how to do this in Swift 4.0(also work in Swift 3.2).
Jef's answer helped here, with slight additions.
Now go through the 'codeForCountryDictionary' with the name of the country for which you require the code, for example,
would yield the result as 'ES', which is the 2 letter country code for spain.
here is Daxesh Negar code in swift 3