Confirmation Dialogs
Offer destructive choices with confirmationDialog.
Confirmation Dialogs is a free SwiftUI Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is a Confirmation Dialog?
A confirmation dialog is an action sheet that slides up with a list of choices, perfect for offering several options at once. 🗂️
Dialog vs Alert
An alert centers on screen for one key decision. A dialog rises from the bottom and suits a menu of related actions instead.
Triggered by a Boolean
Like sheets and alerts, a dialog opens when a boolean state turns true. Store the flag and flip it from a button tap.
@State private var showDialog = falseThe confirmationDialog Modifier
Attach confirmationDialog to a view with a title and a boolean binding. SwiftUI presents the choices when the flag is true.
.confirmationDialog("Choose", isPresented: $showDialog) {
Button("Photo Library") { }
}Listing Choices as Buttons
Each option is a button inside the dialog. SwiftUI stacks them and runs the action of whichever one the user taps.
Button("Camera") { }
Button("Photo Library") { }A Destructive Option
Use the .destructive role for risky choices like delete. The button turns red so users notice before committing.
Button("Delete Account", role: .destructive) { }The Cancel Button
SwiftUI adds a Cancel button automatically. You can also supply your own with role .cancel to control its wording.
Button("Not now", role: .cancel) { }Adding a Title Message
Pass a message closure to explain the choice. It shows as a short caption above the buttons to guide the decision.
.confirmationDialog("Remove item?", isPresented: $show) {
Button("Remove", role: .destructive) { }
} message: {
Text("You can add it again later.")
}Reacting to a Choice
Each button's action runs on tap, then the dialog closes. Put the matching logic, like pick or delete, inside that closure.
Button("Save") { saveDocument() }Dialogs Adapt by Device
On iPhone a dialog rises as an action sheet. On iPad and Mac it appears as a popover near the control that opened it.
When to Use a Dialog
Reach for a dialog when a single tap could mean several things, like sharing or choosing an image source. It keeps options tidy.
Quick Check
When is a confirmation dialog the better choice over an alert?
Recap: Dialogs
You can now present a confirmation dialog from a boolean, list action buttons, and mark destructive choices in red. You finished the course! 🎉
Frequently asked questions
Is the “Confirmation Dialogs” lesson free?
Yes — the full text of “Confirmation Dialogs” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “Confirmation Dialogs”?
Offer destructive choices with confirmationDialog. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Confirmation Dialogs” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Presenting a Sheet
- Detents & Drag Indicators
- Alerts with Actions
- Confirmation Dialogs