I was exploring first()
and last()
. first()
is working fine but not able to understand the behaviour of last()
. Tried all possible way i can but not getting anything inside sink
. Please let let me know what missed?
import Combine
final class FirstLastDemo {
@Published var pubOne: Int = 0
@Published var pubTwo: Int = 0
private var cancellables = Set<AnyCancellable>()
init() {
$pubOne
.first()
.sink { value in
print("Output pubOne:", value)
}
.store(in: &cancellables)
$pubTwo
.last()
.sink { value in
print("Output pubTwo:", value)
}
.store(in: &cancellables)
}
}
let demo = FirstLastDemo()
(1..<3).forEach {
demo.pubOne = $0 // Working as expected
}
(1..<3).forEach {
demo.pubTwo = $0 // No update in `sink`
}