0

I was reading that SwiftUI limits the amount of alerts per view to 1, so in order to have more than 1 we have to divide it, for example into two buttons. In my view I only need 1 button but have 3 necessary different alerts and only 1 works. How can I use them without creating extra invisible buttons or fancy if statements using another view?

This is an example of what I have:

Button(action: {
    // ...
}) {
    Text("Some text")
        .alert(isPresented:$someVar1) {
            Alert(
                title: Text("..."),
                message: Text("..."),
                dismissButton: .default(Text("Ok"))
            )
        }
        .alert(isPresented:$someVar2) {
            Alert(
                title: Text("..."),
                message: Text("..."),
                dismissButton: .default(Text("Ok"))
            )
        }
        .alert(isPresented:$someVar3) {
            Alert(
                title: Text("..."),
                message: Text("..."),
                dismissButton: .default(Text("Ok"))
            )
        }
}
Arturo
  • 3,254
  • 2
  • 22
  • 61

0 Answers0