Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save simrandotdev/a2c75747a3b191f7ffca8eff4862cc00 to your computer and use it in GitHub Desktop.

Select an option

Save simrandotdev/a2c75747a3b191f7ffca8eff4862cc00 to your computer and use it in GitHub Desktop.
Starter Code for video transformTo from a data object to Codable Models
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