Skip to content

Instantly share code, notes, and snippets.

@Andrea-Scuderi
Last active August 1, 2019 10:22
Show Gist options
  • Save Andrea-Scuderi/5072d81b2d73f385d07ac317e657de53 to your computer and use it in GitHub Desktop.
Save Andrea-Scuderi/5072d81b2d73f385d07ac317e657de53 to your computer and use it in GitHub Desktop.
Part 8
// Combining login and postTodo in a single call
func post(email: String, password: String, todo: Todo) -> AnyPublisher<Todo, Error>? {
return login(email: email, password: password)
.map { token -> String in
return token.string
}
.flatMap { (token) -> AnyPublisher<Todo, Error> in
return postTodo(authToken: token, todo: todoList[1])
}
.eraseToAnyPublisher()
}
let cancellablePost = post(email: "[email protected]", password: "password2", todo: todoList[0])?
.sink(receiveCompletion: { (completion) in
switch completion {
case .failure(let error):
print(error)
case .finished:
print("GET - DONE")
}
}, receiveValue: { response in
print(response)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment