TechnologiesSwiftUIPresentation and Dialogs

DialogSeverity struct

iOSmacOStvOSwatchOSvisionOSiOS 17.0+✓ renders

The severity of an alert or confirmation dialog.

How it works

DialogSeverity describes how serious the consequences of a confirmation dialog or alert are, letting the system adjust the dialog's presentation to match the weight of the decision. SwiftUI uses this severity to style and emphasize a dialog appropriately, for example by giving a destructive or irreversible action more visual prominence than a routine one. Reach for it when the standard alert presentation doesn't convey enough urgency, and you want the platform to signal to the person that they're about to do something consequential.

  1. Choose a severity constant

    DialogSeverity is a struct that exposes its values as type properties rather than something you construct directly. Use .critical to mark a dialog as describing a serious, often irreversible outcome, or the default .standard for ordinary confirmations. In the example, .critical flags the file-deletion alert as high-stakes.

  2. Apply it with dialogSeverity(_:)

    You attach a severity to a presentation by calling the dialogSeverity(_:) modifier on the same view that presents the dialog, passing one of the constants. Here .dialogSeverity(.critical) sits alongside the .alert("Delete File?", isPresented:) modifier so the severity travels with that alert.

  3. Pair it with the presenting modifier

    DialogSeverity only takes effect on a view that actually presents a confirmation dialog or alert, so it works in concert with modifiers like alert(_:isPresented:). The $showing binding drives whether the dialog appears, and the severity shapes how it looks once it does.

  4. Reinforce intent with button roles

    Severity complements, rather than replaces, the per-button roles inside the dialog. The .destructive role on the Button("Delete") and the .cancel role on Button("Cancel") describe each action, while .critical describes the overall gravity of the whole dialog.

Try it — Change .dialogSeverity(.critical) to .dialogSeverity(.standard) and re-present the alert to see how the system de-emphasizes the same dialog when it's no longer marked as serious.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

DialogSeverity.swift
struct DialogSeverityDemo: View {
    @State private var showing = true

    var body: some View {
        VStack {
            Text("Deleting this file is permanent.")
        }
        .padding()
        .alert("Delete File?", isPresented: $showing) {
            Button("Delete", role: .destructive) { }
            Button("Cancel", role: .cancel) { }
        } message: {
            Text("This action cannot be undone.")
        }
        .dialogSeverity(.critical)
    }
}
Live preview
Deleting this file is permanent. Delete File? Cancel Delete
Deleting this file is permanent. Delete File? Cancel Delete
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →