view LazyBear/Views/Profile/Networking/Profile.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 4effac4733b0
children
line wrap: on
line source

//
//  Profile.swift
//  LazyBear
//
//  Created by Dennis Concepción Martín on 7/5/21.
//

import SwiftUI
import Alamofire

class Profile: ObservableObject {
    @Published var showView = false
    @Published var data = ProfileResponse()
    
    func request(_ url: String, _ requestType: RequestType) {
        AF.request(url).responseDecodable(of: ProfileResponse.self) { response in
            if let value = response.value {
                switch requestType {
                case .initial:
                    self.data = value
                default:
                    self.data = value
                }

                self.showView = true
            }
        }
    }
}