From 242e2d3c22457e68cbb97097d7a0c2c5ec312a86 Mon Sep 17 00:00:00 2001 From: ad Date: Wed, 18 Apr 2018 22:14:10 +0300 Subject: [PATCH] * currency list --- MTMR/CurrencyBarItem.swift | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/MTMR/CurrencyBarItem.swift b/MTMR/CurrencyBarItem.swift index 7636c84..584f9b9 100644 --- a/MTMR/CurrencyBarItem.swift +++ b/MTMR/CurrencyBarItem.swift @@ -12,15 +12,39 @@ import CoreLocation class CurrencyBarItem: NSCustomTouchBarItem { private var timer: Timer! private var interval: TimeInterval! + private var prefix: String private var from: String private var to: String private let button = NSButton(title: "", target: nil, action: nil) + private let currencies = [ + "USD": "$", + "EUR": "€", + "RUB": "₽", + "JPY": "¥", + "GBP": "₤", + "CAD": "$", + "KRW": "₩", + "CNY": "¥", + "AUD": "$", + "BRL": "R$", + "IDR": "Rp", + "MXN": "$", + "SGD": "$", + "CHF": "Fr." + ] + init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) { self.interval = interval self.from = from self.to = to + if let prefix = currencies[from] { + self.prefix = prefix + } else { + self.prefix = from + } + super.init(identifier: identifier) button.bezelColor = .clear @@ -55,7 +79,7 @@ class CurrencyBarItem: NSCustomTouchBarItem { } if value != nil { DispatchQueue.main.async { - self.setCurrency(text: "\(self.from)\(value!)") + self.setCurrency(text: "\(value!)") } } } catch let jsonError { @@ -68,6 +92,6 @@ class CurrencyBarItem: NSCustomTouchBarItem { } func setCurrency(text: String) { - button.title = text + button.title = "\(self.prefix)\(text)" } }