complete SwiftUI beginner here. I'm looking at this example and I'm trying to understand the lifecycle of @state variables.
showingAlert is initialized as false and is set to true when the button is tapped.
the part that I have trouble wrapping my head around is why does it reset back to false when the alert is dismissed? I do not set that to false anywhere.
I expected it to remain true
@State private var showingAlert = false
var body: some View {
Button(action: { self.showingAlert = true }
) {
Text("Show Alert")
}
.alert(isPresented: $showingAlert) {
Alert(title: Text("Important message"))
}
}