CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
When I try to use WithLatestFrom with two PassthroughSubject. It works very well.
let first = PassthroughSubject<Int, Never>()
let second = PassthroughSubject<String, Never>()
var cancellables = Set<AnyCancellable>()
first
.withLatestFrom(second)
.sink(receiveCompletion: { print($0) }, receiveValue: { print($0) })
.store(in: &cancellables)
first.send(1)
second.send("one")
first.send(2)
second.send("two")
Outputs
one
But if I change second from PassthroughSubject to @Published it will not work
let first = PassthroughSubject<Int, Never>()
@Published var second: String = ""
first
.withLatestFrom(second.publisher)
.sink(receiveCompletion: { print($0) }, receiveValue: { print($0) })
.store(in: &cancellables)
first.send(1)
second = "one"
first.send(2)
second = "two"
Outputs will be empty
Someone can help/explain for me how to use WithLatestFrom with a @Published?
When I try to use
WithLatestFrom
with twoPassthroughSubject
. It works very well.Outputs
But if I change
second
fromPassthroughSubject
to@Published
it will not workOutputs will be empty
Someone can help/explain for me how to use
WithLatestFrom
with a @Published?