1

is there a way to obtain CountryCode from CurrencyCode? Most resources here and here demonstrates getting currencyCode from countryCode, or obtained the countryCode by using currentLocale instead.

My code so far:

let locale = NSLocale(localeIdentifier: "CNY")
print(locale.displayName(forKey: NSLocale.Key.countryCode, value: "CNY"))

Note that I am not using currentLocale to obtain the countryCodes as the currencies are location independent. Thanks.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
Koh
  • 2,687
  • 1
  • 22
  • 62
  • 2
    What country would you expect to get for `EUR`? You can get all countries, get their currencies and filter out the ones with different currency. – Sulthan Jan 07 '18 at 13:03
  • @Sulthan It varies, users are able to define their 'Home Country'. So it could be any country from the EU region. – Koh Jan 07 '18 at 13:06
  • You are trying to map currency to country. That has nothing to do with home countries. The problem is that the result can be multiple countries, that's why there is no clear mapping. However, you can list all the countries and get only the ones with the specified currency. – Sulthan Jan 07 '18 at 13:08
  • @Sulthan yes, thanks for your advice. After giving it much thought I think I'll have to go with your approach. Thanks – Koh Jan 07 '18 at 13:29

0 Answers0