🎛️Confirmation Dialog

struct ConfirmView: View {
// ⭐️ confirmation dialog on/off switch
@State private var isShowingDialog = false
var body: some View {
Button("Delete", role: .destructive) {
isShowingDialog = true // ⭐️ show dialog
}
.buttonStyle(.borderedProminent)
// ------------------------------
// ⭐️ confirmation dialog
// ------------------------------
.confirmationDialog(
"Are you sure to delete the data?", // title
isPresented: $isShowingDialog, // on/off
titleVisibility: .visible
) {
Button("confirm", role: .destructive) {
print("data deleted ...")
}
}
}
}Last updated