view LazyBear/Views/Networking/HomeData.swift @ 328:240b88e3e53e

Testing networking in HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Tue, 30 Mar 2021 23:14:53 +0200
parents
children 2dad5828ccf6
line wrap: on
line source

//
//  HomeData.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 30/3/21.
//

import SwiftUI

class HomeData: ObservableObject {
    @Published var sectorPerformance = [SectorPerformanceModel]() { didSet { print(sectorPerformance) }}
    
    
    let baseUrl = Bundle.main.infoDictionary?["IEX_URL"] as? String ?? "Empty url"
    let apiKey = Bundle.main.infoDictionary?["IEX_API"] as? String ?? "Empty key"
    
    func getSectorPerformance() {
        let url = "\(baseUrl)/stock/market/sector-performance?token=\(apiKey)"
        request(url: url, model: [SectorPerformanceModel].self) { self.sectorPerformance = $0 }
    }
}