Skip to content

Instantly share code, notes, and snippets.

Last active January 25, 2023 03:08
What would you like to do?
import Foundation
extension Locale {
func localizedCurrencySymbol(forCurrencyCode currencyCode: String) -> String? {
guard let languageCode = languageCode, let regionCode = regionCode else { return nil }
Each currency can have a symbol ($, £, ¥),
but those symbols may be shared with other currencies.
For example, in Canadian and American locales,
the $ symbol on its own implicitly represents CAD and USD, respectively.
Including the language and region here ensures that
USD is represented as $ in America and US$ in Canada.
let components: [String: String] = [
NSLocale.Key.languageCode.rawValue: languageCode,
NSLocale.Key.countryCode.rawValue: regionCode,
NSLocale.Key.currencyCode.rawValue: currencyCode,
let identifier = Locale.identifier(fromComponents: components)
return Locale(identifier: identifier).currencySymbol
Locale.isoCurrencyCodes.compactMap { (code) -> String? in
guard let name = Locale.current.localizedString(forCurrencyCode: code),
let symbol = Locale.current.localizedCurrencySymbol(forCurrencyCode: code)
else {
return nil
return "\(name) - \(symbol) (\(code))"
Copy link

Thanks for this. Do you know a place I could look up the symbols Apple uses?

Copy link

Tulakshana commented Aug 19, 2021

Never mind I figured it out.

import Foundation

func listCountriesAndCurrencies() {
    let localeIds = Locale.availableIdentifiers
    var countryCurrency = [String: String]()
    for localeId in localeIds {
        let locale = Locale(identifier: localeId)

        if let country = locale.regionCode {
            if let currency = locale.currencySymbol {
                countryCurrency[country] = currency

    let sorted = countryCurrency.keys.sorted()
    for country in sorted {
        let currency = countryCurrency[country]!

        print("country: \(country), currency: \(currency)")


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment