Been trying to figure this out for a few days now and it's time I ask for help. I know how to do this with normal Swift but SwiftUI is still a bit different to me at the moment. I have a function that checks if something is true. It goes through 3 if statements, if one is true then it returns a bool I created as true. Once one of the 3 is true, I want a certain Alert to pop up. I have pasted all 3 Alert in the body: some View with the correct variable but it doesn't show any. If I comment out 2 and leave 1 Alert uncommented then it works. So I know my if statements are right. It's just how I'm representing it to the body is where I'm stuck at. See below and if you got an alternative.
func showTip() {
if (stepFive <= Float(18)) {
under = true
}
else if (stepFive >= Float(18) && stepFive <= Float(18.5)) {
thin = true
}
else if (stepFive >= 18.6) && (stepFive <= 24.9) {
healthy = true
}
}
var body: some View {
ZStack {
Color.blue
.edgesIgnoringSafeArea(.all)
.alert(isPresented: $under) {
Alert(title: Text("Results"), message: Text("A of less than 18 means you are under weight. "), dismissButton: .default(Text("OK")))
}
.alert(isPresented: $thin) {
Alert(title: Text("Results"), message: Text("A of less than 18.5 indicates you are thin"), dismissButton: .default(Text("OK")))
}
.alert(isPresented: $healthy) {
Alert(title: Text("Results"), message: Text("A between 18.6 and 24.9 indicates you are at a healthy"), dismissButton: .default(Text("OK")))
}
}