Last active
August 1, 2019 10:22
-
-
Save Andrea-Scuderi/5072d81b2d73f385d07ac317e657de53 to your computer and use it in GitHub Desktop.
Part 8
This file contains 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
// 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