Last active
March 27, 2021 17:03
-
-
Save gtokman/c86fab5505b90846240fb6b2ff401f59 to your computer and use it in GitHub Desktop.
Passthrough subject - combine
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
// Create passthrough subject | |
let todoSubject = PassthroughSubject<Todo, Never>() | |
// Release subscription from memory when done | |
var cancellable: AnyCancellable? | |
// Subscribe to updates | |
cancellable = todoSubject | |
.sink { todo in | |
print("New todo to add to table view:", todo.task) | |
} | |
// Imagine we had UI for adding a todo | |
let newTodo = Todo(task: "Groceries") | |
// Publish new todo | |
todoSubject.send(newTodo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment