SwiftUI: iOS Confirmation Alert (Confirm + Cancel)
November 11, 2025·1 min read·by dockui

Deleting data, overwriting a file, leaving a group, resetting settings — these should require an explicit “Yes, I mean it.” SwiftUI gives us this structure with the built-in .alert modifier.
Implementation
Code Snippet
You show the alert by toggling a boolean.
SwiftUI handles the presentation lifecycle for you.
Destructive variant (when the action is dangerous)
Use role: .destructive when the user is about to lose something.
Code Snippet
Apple’s HIG expects this.
Users instantly understand red = irreversible.
Pairing confirmation with haptics (good UX)
Good mobile apps give “feel” to the user’s confirmation. One line:
Code Snippet
You can fire that inside your confirm callback.
Best practices for developers
- always require confirmation before deleting something
- make the title of the alert specific (“Delete photo?” not “Are you sure?”)
- avoid alerts for navigation — alerts are for commit actions
Similar Blogs
View All Articles
SwiftUI: IOS Haptic Feedback Guide 2026
Add click to vibrate haptic feedback in SwiftUI. Full guide to UIImpactFeedbackgenerator, success, error, selection, and tap vibration patterns with code.

SwiftUI: How To Reset a Form
Learn how to reset a SwiftUI form with one line. Clear text fields instantly using @State or a form model. Simple copy/paste SwiftUI code examples.

SwiftUI: How To Toggle a Switch Programmatically
Learn how to toggle a SwiftUI switch programmatically with @State and @Binding. Simple examples with code to trigger Toggle from buttons or other views.

How to optimize your SwiftUI app in 2026
Discover top strategies to optimize your SwiftUI app in 2026, enhancing performance, responsiveness, and maintainability with modern concurrency.
Code copied to clipboard!