Skip to content

Instantly share code, notes, and snippets.

@Edudjr
Last active February 23, 2022 02:06
Show Gist options
  • Save Edudjr/baf235a69201ebbeb70213531c414329 to your computer and use it in GitHub Desktop.
Save Edudjr/baf235a69201ebbeb70213531c414329 to your computer and use it in GitHub Desktop.
struct API {
let url = URL(string: "https://jsonplaceholder.typicode.com/todos/1")!
func loadTodo() async throws -> Todo {
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(Todo.self, from: data)
}
}
class Client1 {
let api = API()
func loadTodo() async {
do {
let todo = try await api.loadTodo()
print(todo)
print("finished")
} catch {
print("failed")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment