Get currency symbols from currency code with swift

前端 未结 11 697
星月不相逢
星月不相逢 2020-12-24 12:21

How can I get the currency symbols for the corresponding currency code with Swift (macOS).

Example:

  • EUR = €1.00
  • USD = $1.00<
11条回答
  •  清歌不尽
    2020-12-24 12:52

    SWIFT4 
    //converting USD to $a and GBP to £ 
    viewDidLoad() 
    { 
     print(getSymbolForCurrencyCode(code: "USD")!) // prints $ 
     print(getSymbolForCurrencyCode(code: "GBP")!) //prints £ 
    }
    
    func getSymbolForCurrencyCode(code: String) -> String? 
    { 
      let locale = NSLocale(localeIdentifier: code)
      return locale.displayName(forKey: NSLocale.Key.currencySymbol, value: code) 
    }
    

提交回复
热议问题