Home > AI > IOS > Combine >

combineLatest(_:)

Example (Apple Official)

The simplest version to combine many publishers.

let pub1 = PassthroughSubject<Int, Never>()
let pub2 = PassthroughSubject<Int, Never>()

let cancellable = pub1
    .combineLatest(pub2)
    .sink { print("Result: \($0).") }


pub2.send(5)
pub1.send(2)
pub2.send(2)

pub1.send(3)
pub1.send(45)

pub2.send(22)
pub1.send(15)

Leave a Reply