Iso country codes - defines codes for the names of countries, dependent territories, and special areas of geographical interest.
Iso language codes - defines the ISO-standard and native names of languages and their ISO 639-1 or -2 codes.
This is an iOS Swift library/class files that does a simple lookup depending on a alpha2, alpha3 or numeric value you give it. Currently it holds all the 249 countries, territories, or areas of geographical interest that are assigned official codes in ISO 3166-1.
It also holds around 500 languages with their associated codes and alternative names and spellings.
This library returns ISO codes, names and currencies for countries, and languages/ISO language codes
-
Find by alpha-2, alpha-3 or numeric (String - yes I know...)
-
Search by (partial) name, case- and diacritic insensitive
-
Search by currency code
-
Search by phone dialing code (+31 for Netherlands, +1 for USA, etc...)
-
Retrieve a corresponding emoji flag for a country code.
-
Find languages by ISO-639-2(B), ISO-639-2(T) or ISO-639-1
-
Search by (partial) name, case- and diacritic insensitive
You can search via numeric, alpha-2 or alpha-3 format. Searching an ISO code returns a struct.
print(IsoCountryCodes.find(key: "020").name) //Andorra
print(IsoCountryCodes.find(key: "TK").name) //Tokelau
print(IsoCountryCodes.find(key: "TKL").currency) //NZD
You can also search by country name, currency or calling/dialing code:
dump(IsoCountryCodes.searchByName("Netherlands")
print(IsoCountryCodes.searchByCurrency("EUR").count ) // 31
print(IsoCountryCodes.searchByCallingCode("+31").first ) // Netherlands
let country = IsoCountryCodes.searchByName("Netherlands")
dump(country) // This dumps the full struct in console
This returns a IsoCountryInfo
struct:
▿ IsoCountryCodes.IsoCountryInfo
- name: Netherlands
- numeric: 528
- alpha2: NL
- alpha3: NLD
- calling: +31
- currency: EUR
- continent: EU
You can also search languages by country name or ISO-639-1 or ISO-639-2 Code,
dump(IsoLanguageCodes.searchByNativeName("Deutsch")
print(IsoLanguageCodes.searchByISO6392B("ger").first ) // German
let language = IsoLanguageCodes.searchByIsoName("German")
dump(language) // This dumps the full struct in console
This returns a IsoLanguageInfo
struct:
▿ IsoLanguageCodes.IsoLanguageInfo
- isoName: German
- nativeName: Deutsch
- iso6391: de
- iso6392T: deu
- iso6392B: ger
Searching by name is case- and diacritic insensitive:
dump(IsoCountryCodes.searchByName("netherlands"))
dump(IsoCountryCodes.searchByName("NETHERLANDS"))
dump(IsoCountryCodes.searchByName("Réunion"))
dump(IsoCountryCodes.searchByName("Reunion"))
If no full match is found, a partial match is tried:
// Full name is "Venezuela, Bolivarian Republic of"
dump(IsoCountryCodes.searchByName("Venezuela"))
but nothing is returned if the search results would be ambiguous:
// There are two Virgin Islands country codes:
// "Virgin Islands, British" and "Virgin Islands, U.S."
dump(IsoCountryCodes.searchByName("Virgin Islands"))
Retrieve a corresponding emoji flag from a country code. (Thanks to @lorismaz for this addition!)
let emojiString = IsoCountries.flag(countryCode: "NL")
// Prints 🇳🇱
or
let emojiString = IsoCountryCodes.find(key: "USA").flag
// Prints 🇺🇸
Copy/add files to your project
The 'do-whatever-you-please-with-it license. Use it or abuse it. Just keep my name at the top of the files.