Alerts, Sheets and Confirmation Dialogs

IOS Development 10 min min read Updated: Nov 16, 2026 Beginner
Alerts, Sheets and Confirmation Dialogs
Beginner Topic 8 of 9

Alert

swift struct AlertDemo: View { @State private var showAlert = false var body: some View { Button("Delete account") { showAlert = true } .alert("Delete account?", isPresented: $showAlert) { Button("Delete", role: .destructive) { deleteAccount() } Button("Cancel", role: .cancel) { } } message: { Text("This cannot be undone.") } } func deleteAccount() { } }

Confirmation Dialog (Action Sheet)

swift @State private var showOptions = false Button("Photo options") { showOptions = true } .confirmationDialog("Choose", isPresented: $showOptions, titleVisibility: .visible) { Button("Take photo") { } Button("Choose from library") { } Button("Remove", role: .destructive) { } }

Sheet

swift struct SheetDemo: View { @State private var showSheet = false var body: some View { Button("Open settings") { showSheet = true } .sheet(isPresented: $showSheet) { SettingsView() .presentationDetents([.medium, .large]) // half height or full .presentationDragIndicator(.visible) } } } struct SettingsView: View { @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { Text("Settings go here") .navigationTitle("Settings") .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } } } }
dismiss: @Environment(\.dismiss) gives the sheet a way to close itself. Call dismiss() and SwiftUI handles the rest.

Sheet with an Item

swift struct Book: Identifiable { let id = UUID(); let title: String } @State private var selected: Book? List(books) { book in Button(book.title) { selected = book } } .sheet(item: $selected) { book in // opens when selected is not nil Text("Details of \(book.title)") }

Full Screen Cover and Popover

swift .fullScreenCover(isPresented: $showOnboarding) { OnboardingView() } .popover(isPresented: $showTip) { Text("Tap to learn more").padding() }

ProgressView

swift ProgressView() // spinner ProgressView("Loading...") ProgressView(value: 0.6) // bar ProgressView(value: downloaded, total: 100)
ComponentUse for
AlertShort important message or yes/no question
Confirmation dialogChoose between several actions
SheetA related task on a card
Full screen coverImmersive flow like onboarding or camera

Conclusion

Alerts interrupt, dialogs offer choices, sheets host sub-tasks and covers take the whole screen. Control them with a Boolean or an optional item.

Quick Summary: Use alert, confirmationDialog, sheet and fullScreenCover with isPresented or item bindings, and dismiss with @Environment(\.dismiss).

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators