Last active
February 23, 2022 02:06
-
-
Save Edudjr/baf235a69201ebbeb70213531c414329 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
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