Hi having problems with onappear and ondisappear. Just want to get get these closures to work to print out a statement in my console and no luck. I’m not sure if having a function is the problem. Any suggestions are appreciated. Here is my code:
import SwiftUI
var stopWatch = Stopwatch()
struct Introduction: View {
// @Environment(Stopwatch.self) var stopWatch
var body: some View {
NavigationStack {
VStack {
NavigationLink(destination: FactFinding(), label: { Text("Next Step") })
Button("Start"){stopWatch.start()}
.buttonStyle(.borderedProminent)
Button("Stop"){stopWatch.elapsedTime()}
.buttonStyle(.borderedProminent)
.padding()
}
.onAppear //tried this with onDisappear as well {
print("Introduction appeared!")
}
}
}
}
1