I'm trying to set value to a @State
variable alertText
once a button click action is performed. However it isn't working and value in alertText
isn't getting set.
I'm new to SwiftUI so I think I'm missing something obvious. I would appreciate any help.
struct ContentView: View {
@State private var showSheet = false
@State private var alertText : String = "Initial Value"
var body: some View {
NavigationView{
Button("Show Sheet", action: {
alertText = "Modified Value"
showSheet = true
})
.sheet(isPresented: $showSheet, content: {
Text(alertText)
})
.navigationTitle("Test View")
}
}
}