Combine provides a way to emit values at regular time intervals using:
Timer.publish
This creates a publisher that emits values continuously over time.
Unlike publishers like Just or arrays, a Timer publisher produces an infinite stream.
let timerPublisher = Timer
.publish(every: 1.0, on: .main, in: .common)
Parameters:
every → time interval (seconds)
on → run loop (usually .main)
in → run loop mode
This only creates the publisher — it does not start emitting yet.
To begin emitting values:
.autoconnect()
Example:
let timerPublisher = Timer
.publish(every: 1.0, on: .main, in: .common)
.autoconnect()
This automatically connects and starts the timer.