I have a navigation view consisting of the main ContentView and a TimerView. The TimerView has a timer which correctly increments and also corr
if you have a countdown timer, you define it something like this:
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
...and use it on a Text field for e.g.:
Text("Punkte: \(Punkte.formatnumber())")
.onReceive(timer) { input in
if time < 1 { gameOver() } else { self.time -= TimerToggle ? 1 : 0 }
}
so you only have to set the Toggle in the action of the button:
Button(action: { TimerToggle.toggle() }, label: {
Text("Pause")
})
Much simpler and works in SwiftUI 5.2