Type Method publish(every: tolerance: on: in: options:)
Returns a publisher that repeatedly emits the current date on the given interval.
iOS 7.0+ macOS 10.9+ Mac Catalyst 13.0+ Beta tvOS 9.0+ watchOS 2.0+ Xcode 11.0+ Beta Parameters
The time interval on which to publish events. For example, a value of
publishes an event approximately every half-second.
The allowed timing variance when emitting events. Defaults to
, which allows any variance.
The run loop on which the timer runs.
The run loop mode in which to run the timer.
Scheduler options passed to the timer. Defaults to
nil Return Value
A publisher that repeatedly emits the current date on the given interval.
The return type,
, conforms to Timer .Timer Publisher , which means you must explicitly connect to the Connectable Publisher
publisher to begin publishing events. You can do this with a call to
Timer , or by using connect() to automatically connect when a subscriber attaches, as shown here: autoconnect()
cancellable = Timer.publish(every: 1, on: .main, in: .common)
print ("timer fired: \($0)")
Topics Declaring Publisher Topography Creating a Timer Publisher See Also Firing Messages as a Combine Publisher
This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.
Learn more about using Apple's beta software