โ†

SwiftUI: Confirm delete dialog

This can be used generally, not just for deleting.

Create a state variable @State var presentConfirmDelete: Bool = false and set that to true when you want to confirm the deletion, probably from within a button.

At the bottom of the view create a confirmationDialog {} modifier that react based on the presentConfirmDelete variable. Within that create two buttons with a .role of either .destructive or .cancel, and within those do your actions.

.confirmationDialog("", isPresented: $presentConfirmReset) {
    Button("Try remembering anew", role: .destructive) { /* something */ }
    Button("Cancel", role: .cancel) { /* something */ }
}
swiftui
I've removed disqus comments
Instead, press this
to express thanks
So far, 0 people have pressed the octopus
I'm no longer visiting the Reddit tabloid. It's anger-inducing and divisive
I'm writing small thoughts here