Created
April 18, 2020 08:58
-
-
Save FitzAfful/c7a929e1e7f848e0cd47bb85628d0762 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Alamofire | |
import Combine | |
class CombineViewModel: ObservableObject { | |
var apiManager: APIManager? | |
@Published var employees: [Employee] = [] //1 | |
init(manager: APIManager = APIManager()) { | |
self.apiManager = manager | |
} | |
func setAPIManager(manager: APIManager) { | |
self.apiManager = manager | |
} | |
func fetchEmployees() { | |
self.apiManager!.getEmployees { (result: DataResponse<EmployeesResponse, AFError>) in | |
switch result.result { | |
case .success(let response): | |
if response.status == "success" { | |
self.employees = response.data | |
} | |
case .failure: | |
print("Failure") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment