2

For an app I need the users to create addresses. It is important that the addresses are valid and include an ISO 3166 ALPHA-2 country code as well as an ISO 3166-2 code for the province, state, etc.

I can use NSLocale to get all country codes and the localized names for a country code but is there a similar way to get the codes and names (they doesn't have to be localized) for the subdivisions of a country or do I have to create that massive dictionary by myself? :D

Thank you in advance

Dennis
  • 200
  • 15
  • You either need to create it yourself or find an API that provides that information – Scriptable Mar 02 '20 at 10:43
  • You could find a json file with dictionary of all code. Add that file to your project Bundle. Fetch data from the bundle file. You then just need to parse that data in a struct. Use JSONDecoder for decoding json to struct. – Frankenstein Mar 02 '20 at 10:52
  • So far this is the best library with multiple features, even you can find by `ALPHA-2`. hope this will serve your purpose. https://github.com/funky-monkey/IsoCountryCodes – Newbie Mar 02 '20 at 10:53
  • You can always check out [datahub.io](https://datahub.io/collections/reference-data) – Joakim Danielson Mar 02 '20 at 11:12
  • @Newbie That library brings a lot of fun features but Swift brings a list with all country codes and localized names as well and that is all I need for the countries. As for the ISO 3166-2 codes I apparently have to create the dictionary by myself but thanks for your ideas especially datahub.io is an awesome source I didn't know – Dennis Mar 02 '20 at 18:07

0 Answers0