Skip to content

Instantly share code, notes, and snippets.

@Edudjr
Created February 23, 2022 01:22
Show Gist options
  • Save Edudjr/b962ba14622761116d7d0384d3b61893 to your computer and use it in GitHub Desktop.
Save Edudjr/b962ba14622761116d7d0384d3b61893 to your computer and use it in GitHub Desktop.
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