I have been trying to accomplish two main goals that I'm having a headache with. Sorry if it's a simple fix, I am a still bit new to Swift/SwiftUI.
- Trigger an action after a certain time has elapsed.
- Trigger an
@State
to change value based on how much time has passed.
I've searched through Stack Overflow and found answers suggesting to use a timer:
struct CurrentDateView : View {
@State var now = Date()
let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect()
var body: some View {
Text("\(now)")
.onReceive(timer) {
self.now = Date()
}
}
}
But how would I incorporate this so that something like @State
can be used change my value to false
after 7.5 seconds has passed:
@State randomTF : Bool = true
Or a Text("Please Enter Above")
to change to Text("Sorry Too Late")
after 7.5 seconds has passed?