ios – Easy methods to get the forex image from Locale Swift

[ad_1]

Making an attempt to make a computed property that present all doable currencies to be proven on a UIPickerView. At present, the symbols I get in my array all the time is ¤ any tricks to make it work?

import UIKit

struct MyCurrency: Codable {
    let code: String
    let title: String
    let image: String
}

var currencies: [MyCurrency] {
    return Locale.Forex.isoCurrencies.compactMap {
        guard let title = Locale.present.localizedString(forCurrencyCode: $0.identifier),
              let image = Locale(identifier: $0.identifier).currencySymbol  else { return nil }
        return MyCurrency(code: $0.identifier, title: title, image: image)
    }
}

print(currencies)

[ad_2]

Leave a Reply