This should be simple but I am hoping to display an alert when a condition is true.(see below) I have seen lots where you used a button to trigger an alert, but I just want an alert to trigger when a condition is met such as in a simple "If" statement. Which should appear as soon as the code is loaded.
import SwiftUI
struct ContentView: View {
@State private var showingAlert = false
var score = 3
var body: some View {
VStack{
if score == 3 {
showingAlert = true
} .alert(isPresented: $showingAlert) {
Alert(title: Text("Hello SwiftUI!"), message: Text("This is some detail message"), dismissButton: .default(Text("OK")))
}
}
}