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: 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.

Animate Number Changes in SwiftUI
Smoothly animate number changes in SwiftUI. Use .contentTransition(.numericText()) on iOS 17+, with clean older fallbacks for pre-17 devices.

SwiftUI vs UIKit in 2025: Which Is Better?
Learn which framework to choose, how to mix both, and when UIKit still makes sense for iOS app development.

How to use @AppStorage in SwiftUI
Learn how to use @AppStorage in SwiftUI to save user settings and preferences easily with UserDefaults
Code copied to clipboard!