Created
August 15, 2020 00:30
-
-
Save simrandotdev/a2c75747a3b191f7ffca8eff4862cc00 to your computer and use it in GitHub Desktop.
Starter Code for video transformTo from a data object to Codable Models
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 UIKit | |
| let url = URL(string: "https://reqres.in/api/users/2")! | |
| URLSession.shared.dataTask(with: url) { (data, response, error) in | |
| if error != nil { | |
| print("Request failed with error: \(error?.localizedDescription)") | |
| return | |
| } | |
| guard let data = data else { | |
| print("Request failed: No Data found") | |
| return | |
| } | |
| }.resume() | |
| struct Response: Codable { | |
| var data: User | |
| } | |
| struct User: Codable { | |
| var id: Int | |
| var email: String | |
| var avatar: String | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment