-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathViewController.swift
More file actions
108 lines (56 loc) · 2.47 KB
/
ViewController.swift
File metadata and controls
108 lines (56 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import UIKit
class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate,CoinManagerApiJson {
//BTC
@IBOutlet weak var btcPriceField: UILabel!
@IBOutlet weak var btccurrencyLabel: UILabel!
@IBOutlet weak var pickerElement: UIPickerView!
//ETC
@IBOutlet weak var etcPriceLabel: UILabel!
@IBOutlet weak var ethCurrencyLabel: UILabel!
//Solana
@IBOutlet weak var solPriceLabel: UILabel!
@IBOutlet weak var solCurrencyLabel: UILabel!
var coinManager = CoinManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
pickerElement.dataSource = self
pickerElement.delegate = self
coinManager.delegate = self
}
func updatePriceETH(_ price: String, _ currentcurrency: String) {
DispatchQueue.main.async {
self.etcPriceLabel.text = price
self.ethCurrencyLabel.text = currentcurrency
}
}
func updatePriceSOL(_ price: String, _ currentcurrency: String) {
DispatchQueue.main.async {
self.solPriceLabel.text = price
self.solCurrencyLabel.text = currentcurrency
}
}
func updatePrice(_ price: String, _ currentcurrency: String) {
DispatchQueue.main.async {
self.btcPriceField.text = price
self.btccurrencyLabel.text = currentcurrency
}
}
func didFailedWithError(error: Error) {
print(error)
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
coinManager.getCoinPrice(for: coinManager.currencyArray[row],coin:"BTC/")
coinManager.getCoinPrice(for: coinManager.currencyArray[row],coin:"ETH/")
coinManager.getCoinPrice(for: coinManager.currencyArray[row],coin:"SOL/")
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return coinManager.currencyArray.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return coinManager.currencyArray[row]
}
}