I'm building the a metronome with swiftUI
I have a @State var that connect to a slider.
@State private var period: Double
Slider(value: period, in: 0.25...5, step: 0.25)
Right now I can only reset the time interval if I restart the metronome.
Button(action: { startStop = !startStop
self.timer = Timer.publish(every: self.period, on: .main, in:.default).autoconnect()
} ){
Text("START/STOP")
}
However, I want to trigger the "self.timer = Timer.publish(...." whenever the slider is moved. Is there a way to trigger an ObservableObject @Published var whenever a @State var is changed? So that I can use ".onReceive()" function to trigger "self.timer = Timer.publish(...."
Thank you