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.
Choose a severity constant
DialogSeverity is a struct that exposes its values as type properties rather than something you construct directly. Use
.criticalto mark a dialog as describing a serious, often irreversible outcome, or the default.standardfor ordinary confirmations. In the example,.criticalflags the file-deletion alert as high-stakes.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.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$showingbinding drives whether the dialog appears, and the severity shapes how it looks once it does.Reinforce intent with button roles
Severity complements, rather than replaces, the per-button roles inside the dialog. The
.destructiverole on theButton("Delete")and the.cancelrole onButton("Cancel")describe each action, while.criticaldescribes the overall gravity of the whole dialog.
.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.
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)
}
}