8

我需要显示货币列表,以便用户可以选择一个。我想包括 iOS 支持的所有货币。

iOS 中有没有办法获取所有受支持货币的代码和名称?

提前致谢!

4

3 回答 3

8

给你:

NSLocale *locale = [NSLocale currentLocale];
for (NSString *code in [NSLocale ISOCurrencyCodes]) {
    NSLog(@"%@ : %@", code, [locale displayNameForKey:NSLocaleCurrencyCode value:code]);
}
于 2013-01-15T18:23:16.040 回答
8

斯威夫特 5

let currencys = Locale.isoCurrencyCodes

所有唯一货币的数组:

let list = ["AED - AED","AFN - ؋","ALL - ALL","AMD - ֏","ANG - ANG","AOA - Kz","ARS - $","AUD - $","AWG - AWG","AZN - ₼","BAM - KM","BBD - BBD","BDT - ৳","BGN - BGN","BHD - د.ب.‏","BIF - FBu","BMD - $","BND - $","BOB - Bs","BRL - R$","BSD - $","BTN - Nu.","BWP - P","BYN - Br","BZD - $","CAD - CA$","CDF - FC","CHF - CHF","CLP - $","CNY - ¥","COP - $","CRC - ₡","CUP - $","CVE - ​","CZK - CZK","DJF - Fdj","DKK - DKK","DOP - RD$","DZD - DA","EGP - ج.م.‏","ERN - Nfk","ETB - Br","EUR - €","FJD - $","FKP - FKP","GBP - £","GEL - ₾","GHS - GH₵","GIP - £","GMD - GMD","GNF - GNF","GTQ - Q","GYD - GYD","HKD - HK$","HNL - L","HRK - HRK","HTG - HTG","HUF - Ft","IDR - Rp","ILS - ₪","INR - ₹","IQD - د.ع.‏","IRR - ریال","ISK - ISK","JMD - $","JOD - د.أ.‏","JPY - ¥","KES - Ksh","KGS - сом","KHR - ៛","KMF - CF","KPW - KPW","KRW - ₩","KWD - د.ك.‏","KYD - KYD","KZT - ₸","LAK - ₭","LBP - ل.ل.‏","LKR - රු.","LRD - $","LYD - د.ل.‏","MAD - MAD","MDL - L","MGA - Ar","MKD - ден","MMK - K","MNT - ₮","MOP - MOP$","MRU - أ.م.","MUR - Rs","MVR - ރ.","MWK - MK","MXN - $","MYR - RM","MZN - MTn","NAD - $","NGN - ₦","NIO - C$","NOK - NOK","NPR - नेरू","NZD - $","OMR - ر.ع.‏","PAB - B/.","PEN - S/","PGK - K","PHP - ₱","PKR - ر","PLN - zł","PYG - Gs.","QAR - ر.ق.‏","RON - RON","RSD - RSD","RUB - RUB","RWF - RF","SAR - ر.س.‏","SBD - $","SCR - SR","SDG - ج.س.","SEK - kr","SGD - $","SHP - £","SLL - SLL","SOS - S","SRD - SRD","SSP - £","STN - Db","SYP - LS","SZL - E","THB - ฿","TJS - сом.","TMT - TMT","TND - DT","TOP - T$","TRY - ₺","TTD - TTD","TWD - $","TZS - TSh","UAH - UAH","UGX - USh","USD - $","UYU - $","UZS - soʻm","VND - ₫","VUV - VT","WST - WS$","XAF - FCFA","XCD - $","XOF - CFA","XPF - FCFP","YER - ر.ي.‏","ZAR - R","ZMW - K"]
于 2019-12-16T13:57:40.193 回答
0

您可以使用 获取所有ISO代码的列表Locale

下面的代码将货币的所有 ISO 代码作为字符串数组返回。

Locale.isoCurrencyCodes

您还可以将以下代码段复制到您的代码中

struct Currency {
    let name: String
    let code: String
}

extension Currency {
    static var allCurrencies: [Currency] {
        let currencies: [Currency] = Locale.isoCurrencyCodes.compactMap {
            guard let name = Locale.current.localizedString(forCurrencyCode: $0) else {
                return nil
            }
            return Currency(name: name, code: $0)
        }
        return currencies
    }
}

这将为您提供货币类型的所有货币列表,您可以轻松访问名称、代码。此外,如果需要,您也可以附加符号。

于 2021-11-24T10:01:36.847 回答