The code below only shows the false alert. Is there a way to make the alert match the IF condition?
@State var showTrueAlert = false
@State var showFalseAlert = false
var body: some View {
Button(action: {
let isTrue = Bool.random()
if isTrue {
self.showTrueAlert = true
print("True Alert")
} else {
self.showFalseAlert = true
print("False Alert")
}
}) {
Text("Random Alert")
.font(.largeTitle)
}
.alert(isPresented: $showTrueAlert) {
Alert(title: Text("True"))
}
.alert(isPresented: $showFalseAlert) {
Alert(title: Text("False"))
}
}