Skip to content

Timer Dynamic Property

Vatsal Manot edited this page Jun 25, 2020 · 3 revisions

TimerState

Working with timers in SwiftUI can often require a fair amount of boilerplate, and a simpler API is desirable. This is where @TimerState comes in.

Usage:

struct ContentView: View {
    @TimerState(interval: 2) var timeElapsed: Int // interval is the time interval in seconds
    
    var body: some View {
        Text("\(timeElapsed * 2) second(s) have elapsed")
    }
}