comparison LazyBear/Views/Company/Networking/Company.swift @ 450:4b8031e696e8

Change Bazooka to Alamofire Alamofire is compatible with WatchOS and MacOS
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sat, 26 Jun 2021 16:36:53 +0200
parents 01fa77358b82
children
comparison
equal deleted inserted replaced
449:4255f94d0767 450:4b8031e696e8
4 // 4 //
5 // Created by Dennis Concepción Martín on 20/6/21. 5 // Created by Dennis Concepción Martín on 20/6/21.
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 import Bazooka 9 import Alamofire
10 10
11 class Company: ObservableObject { 11 class Company: ObservableObject {
12 @Published var showView = false 12 @Published var showView = false
13 @Published var showChart = true /// To show a ProgressView when the chart is refreshed (Date range selected) 13 @Published var showChart = true /// To show a ProgressView when the chart is refreshed (Date range selected)
14 @Published var data = CompanyResponse() 14 @Published var data = CompanyResponse()
15 15
16 func request(_ url: String, _ requestType: RequestType) { 16 func request(_ url: String, _ requestType: RequestType) {
17 if requestType == .refresh { self.showChart = false } 17 if requestType == .refresh { self.showChart = false }
18 let bazooka = Bazooka() 18 AF.request(url).responseDecodable(of: CompanyResponse.self) { response in
19 bazooka.request(url: url, model: CompanyResponse.self) { response in 19 if let value = response.value {
20 switch requestType { 20 switch requestType {
21 case .initial: 21 case .initial:
22 self.data = response 22 self.data = value
23 case .streaming: 23 case .streaming:
24 self.data.quote = response.quote 24 self.data.quote = value.quote
25 case .refresh: 25 case .refresh:
26 self.data.historicalPrices = response.historicalPrices 26 self.data.historicalPrices = value.historicalPrices
27 }
28
29 self.showView = true
30 self.showChart = true
27 } 31 }
28
29 self.showView = true
30 self.showChart = true
31 } 32 }
32 } 33 }
33 } 34 }