I want to make an application where the users will press one button, and then, when they have chosen an option, another alerts pops up. When I try something similar to this;
struct ContentView: View {
@State private var showingAlert = false
@State private var showingAlertII = false
var body: some View {
Button(action: {
self.showingAlert = true
}, label: {
Text("button")
.alert(isPresented: $showingAlert) {
Alert(title: Text("Option one or two"), message: Text("choose"), primaryButton: .default(Text("one"), action: {
// do some specific actions
self.showingAlertII = true
}), secondaryButton: .default(Text("two"), action: {
//do some other stuff
self.showingAlertII = true
}))
}
.alert(isPresented: $showingAlertII) {
Alert(title: Text("Option A or B"), message: Text("choose"), primaryButton: .default(Text("Split"), action: {
// do something
}), secondaryButton: .default(Text("B"), action: {
//do something
}))
}
})
No alert is showing. Note that there is another tutorial: How can I have two alerts on one view in SwiftUI? similar to this, however, using .first notation and returning one or another will not work for me because I want both to be shown, one after another.