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!
//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
//Returns the user's current locale
let locale = Locale.current
//Returns the local currency's symbol
//Ex: $
let currencySymbol = locale.currencySymbol!
//Returns the currency code of the locale. Returns nil if the data isn't available
//Ex: USD
let currencyCode = locale.currency!.identifier
3条答案
按热度按时间0dxa2lsx1#
您可以使用以下命令从
(NS)Locale
获取货币符号和代码Swift 1和2
*Swift 3酒店,纽约
Swift 3.1+
这与用户区域格式设置相关,在
iOS
和macOS
中均适用h9vpoimq2#
关于Swift3
2q5ifsrm3#
适用于iOS 16+