I have a navigation view consisting of the main ContentView and a TimerView. The TimerView has a timer which correctly increments and also corr
Having a variable inside a View
which isn't attached to a @State
variable or an @ObservedObject
model doesn't seem to have very well defined documentation - but the general rule is that everything without a @State/@ObservedObject
annotation is essentially throwaway - especially as TimerView
is a struct
and won't be preserved over re-renders.
Timer.TimerPublisher
is a class - so essentially this would boil down to either two use cases
@State
(be aware of strong retention with self
captures - again documentation is thin on how onReceive
stores its connections) var
) and brought in via the init
call for TimerView
That you have @State var secondsElapsed
makes me think it should be transient