I want to add buttons in swiftUI alert at run time. Below code is not working.
struct ContentView: View {
@State private var presentAlert = false
@State private var username: String = ""
var body: some View {
Button("Show Alert") {
presentAlert = true
}
.alert("Login", isPresented: $presentAlert, actions: {
TextField("Username", text: $username)
Button("Cancel", role: .cancel, action: {})
if $username.wrappedValue.count>0 {
Button("Login", action: {})
}
}, message: {
Text("Please enter your username and password.")
})
}
}