Created
April 5, 2020 13:17
-
-
Save lawreyios/3717b6115374365112c55c3826bd78ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Combine | |
import Alamofire | |
class LoginHandler: APIHandler { | |
@Published var woofResponse: WoofResponse? | |
@Published var isLoading = false | |
func getRandomDog() { | |
isLoading = true | |
let url = "https://random.dog/woof.json" | |
AF.request(url, method: .get).responseDecodable { [weak self] (response: DataResponse<WoofResponse, AFError>) in | |
guard let weakSelf = self else { return } | |
guard let response = weakSelf.handleResponse(response) as? WoofResponse else { | |
weakSelf.isLoading = false | |
return | |
} | |
weakSelf.isLoading = false | |
weakSelf.woofResponse = response | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment