Created
February 23, 2022 01:22
-
-
Save Edudjr/b962ba14622761116d7d0384d3b61893 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() -> AnyPublisher<Todo, Error> { | |
URLSession.shared.dataTaskPublisher(for: url) | |
.map { $0.data } | |
.decode(type: Todo.self, decoder: JSONDecoder()) | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment