Fast delivery of local currency

I am setting up a little shopping store for purchases in several countries. How can I find out that I have to show the price in dollars, euros, etc ... I think this is due to the localeIdentifier, but I'm not sure how to handle this

+8
xcode currency swift locale
source share
2 answers

You can get the currency symbol and code from (NS)Locale using

Swift 1 and 2

 let locale = NSLocale.currentLocale() let currencySymbol = locale.objectForKey(NSLocaleCurrencySymbol)! let currencyCode = locale.objectForKey(NSLocaleCurrencyCode)! 

Swift 3

 let locale = Locale.current() let currencySymbol = locale.object(forKey: .currencySymbol)! let currencyCode = locale.object(forKey: .currencyCode)! 

Swift 3.1

 let locale = Locale.current let currencySymbol = locale.currencySymbol! let currencyCode = locale.currencyCode! 

This correlates with custom region format settings and works on both iOS and macOS

+33
source share

for swift3

 //User region setting return let locale = Locale.current //NSLocale.current //Returns true if the locale uses the metric system (Note: Only three countries do not use the metric system: the US, Liberia and Myanmar.) let isMetric = locale.usesMetricSystem //Returns the currency code of the locale. For example, for "zh-Hant-HK", returns "HKD". let currencyCode = locale.currencyCode //Returns the currency symbol of the locale. For example, for "zh-Hant-HK", returns "HK$". let currencySymbol = locale.currencySymbol 
+2
source share

All Articles