Skip to content

Instantly share code, notes, and snippets.

@nalexn
Last active October 14, 2019 19:58
Show Gist options
  • Save nalexn/250151190009b2806682064a26890f66 to your computer and use it in GitHub Desktop.
Save nalexn/250151190009b2806682064a26890f66 to your computer and use it in GitHub Desktop.
class ValueConsumer {
private var subscription1: AnyCancellable?
private var subscription2: AnyCancellable?
private var subscription3: AnyCancellable?
private let mySubject = CurrentValueSubject<Int, Never>(0)
private var myVar: Int = 0
func consumeValues(publisher1, ...) {
subscription1 = publisher1
.sink { print("New value: \($0)") }
subscription2 = mySubject
.subscribe(publisher2)
subscription3 = publisher3
.assign(to: \.myVar, on: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment