This error occurs with this code and I have no idea what it means:
.alert(isPresented: $showingAlert) {
Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("OK")))
Any help please.
This error occurs with this code and I have no idea what it means:
.alert(isPresented: $showingAlert) {
Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("OK")))
Any help please.
I had this error message because the brackets (the rounded ones) were not correctly paired. Your code works, these versions also work (using code that is not a "one liner" and Editor/Structure/Re-Indent also helps to see what might be wrong :-) ):
.alert(isPresented: $showAlert) {
Alert(title: Text("Title"),
message: Text("An alert"),
primaryButton: .default(Text("OK"), action: {
}),
secondaryButton: .cancel(Text("Cancel"), action: {
})
)
}
or this:
.alert(isPresented: $showAlert) {
Alert(title: Text("Title"),
message: Text("An alert"),
primaryButton: .default(Text("OK")) {
},
secondaryButton: .cancel(Text("Cancel"))
)
}
I had this problem too and Xcode become messy. What I did to fix in in my end was:
First, create the alert in a computed property:
var alert: Alert {
Alert(title: Text("Oops"), message: Text("Error Message"), dismissButton: .default(Text("Dismiss")))
}
Then use the alert property at the end of your superview:
@State var showAlert = false
var body: some View {
ZStack {
...
}.alert(isPresented: $showAlert, content: { self.alert })
}
I hope this solution works for you too.