22
Jan
2021
Timers and countdowns in SwiftUI
swiftui timer combine onreceive publisher tick interval cancelReading time: 1 min
This recipe shows how to implement a timer in SwiftUI in order to update the UI state at a specific interval.
There are two ways of going about it:
- The simple one, with
onReceive
. - A bit more complex, but also more powerful one, using
SimpleTimer
wrapper.
Search our recipes
Check out the companion apps!
Our free companion app and XCode Extension brings 100+ SwiftUI recipes right at your fingertips! Get a preview of it in the Online Companion.
Have a recipe for us?
Get in touch and let's grow the cookbook together!