我正在为多个国家的应用程序商店设立一个小小的。我怎么能弄清楚我必须以美元,欧元等价格出现... 我认为它与localeIdentifier有关,但我不知道如何处理这个
答案 0 :(得分:47)
您可以使用
从"field_name": {
"type": "string",
"index": "not_analyzed"
}
获取货币符号和代码
Swift 1和2
(NS)Locale
Swift 3
let locale = NSLocale.currentLocale()
let currencySymbol = locale.objectForKey(NSLocaleCurrencySymbol)!
let currencyCode = locale.objectForKey(NSLocaleCurrencyCode)!
Swift 3.1
let locale = Locale.current()
let currencySymbol = locale.object(forKey: .currencySymbol)!
let currencyCode = locale.object(forKey: .currencyCode)!
这与用户区域格式设置相关,适用于let locale = Locale.current
let currencySymbol = locale.currencySymbol!
let currencyCode = locale.currencyCode!
和iOS
答案 1 :(得分:5)
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