Alert isn't presenting when we use confirmationDialog in a View Xcode 13

Alert isn't presenting when I use confirmationDialog and alert in a single View.

struct ConfirmationDialog: View {
@State private var showingOptions = false
@State private var showingAlert = false
var body: some View {
VStack {
Button("Show Options") {
showingOptions = true
}
.alert("Alert Title", isPresented: $showingAlert, actions: {
Button {
// Do nothing
} label: {
Text("Okay")
}
}, message: {
Text("Alert Message")
})
.confirmationDialog("Select option", isPresented: $showingOptions, titleVisibility: .visible) {
Button("Show Alert") {
self.showingAlert = true
}
}
}
}
}

I'm getting a console log when confirmationDialog is presented for the first time.

Attempting to present an alert while a confirmation dialog is already presented. This is not supported.

I'm using XCode 13 and iOS 15 simulator. I tried even changing the sequence it didn't worked

Is it a bug in XCode 13 or there are any other ways to fix it.

Link for StackOverflow

Try this:

@State private var showingOptions = false
@State private var showingAlert = false
var body: some View {
VStack {
Button("Show Options") {
showingOptions = true
}
.alert(isPresented: $showingAlert) {
Alert(title: Text("Alert"), message: Text("Message"), dismissButton: .default(Text("OK")))
}
.confirmationDialog("Select option", isPresented: $showingOptions, titleVisibility: .visible) {
Button("Show Alert") {
self.showingAlert = true
}
}
}
}
}

Yes @robnotyou it worked. But that API for showing an alert was deprecated.

.alert(isPresented: $showingAlert) {
Alert(title: Text("Alert"), message: Text("Message"), dismissButton: .default(Text("OK")))
}

https://developer.apple.com/documentation/swiftui/view/alert(item:content:)

@Srikanth_Thangavel Did you find any valuable solution to this problem without making use of the deprecated alert API?

Alert isn't presenting when we use confirmationDialog in a View Xcode 13
 
 
Q