@Craig
It looks like you have two ? buttons on your View so I assume that you want to show a different alert depending on which button is pressed. You can have two alerts but you need to set up a switch to display whichever alert you require. As an example, the following is a means I have used to differentiate between multiple alerts on the same page. This uses an enum which defines the ActiveAlert like this:
enum ActiveAlert {
case errorAuthenticating
case errorBiometrics
case showPlaceDetails
}
Define a State variable for the activeAlert and your showingAlert trigger like this:
@State private var activeAlert: ActiveAlert = .showPlaceDetails
@State private var showingAlert = false
In your code you would set the activeAlert accordingly and showingAlert to true to select the alert you wanted to present.
In my case the alerts were defined like so:
.alert(isPresented: $showingAlert) {
switch activeAlert {
case .showPlaceDetails:
return Alert(title: Text(selectedPlace?.title ?? "Unknown"), message: Text(selectedPlace?.subtitle ?? "Missing place information."), primaryButton: .default(Text("OK")), secondaryButton: .default(Text("Edit")) {
self.showingEditScreen = true
})
case .errorAuthenticating:
return Alert(title: Text("Error"), message: Text("Unable to Authenticate"), dismissButton: .default(Text("OK")))
case .errorBiometrics:
return Alert(title: Text("Error"), message: Text("Biometrics not available"), primaryButton: .default(Text("OK")), secondaryButton: .default(Text("Choose Password")) {
self.choosePassword()
})
}
}
The other alternative is to define a single alert since you also appear to be just advising what is required in each text field. In the button action set the titleText and the messageText and then set showingAlert = true.
For example:
@State private var titleText = ""
@State private var messageText = ""
@State private var showingAlert = false
…
…
…
…
Button(action:{
self.showingAlert = true
self.titleText = "Help
self.messageText = "Enter the Name of your Two Stroke Engine."
}) {
Image(systemName : "questionmark.circle.fill")
.resizable()
.frame(width: 20.0, height: 20.0)
.accentColor(.black)
}
} // End of VStack or HStack
.alert(isPresented: $showingAlert) {
Alert(title: Text(self.titleText), message: Text(self.messageText), dismissButton: .default(Text("Got it!")))
}