<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/dismissalConfirmationDialog(_:shouldPresent:actions:message:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE27dismissalConfirmationDialog_13shouldPresent7actions7messageQr10Foundation23LocalizedStringResourceV_Sbqd__yXEqd_0_yXEtAaBRd__AaBRd_0_r0_lF::OverloadGroup"
  },
  "title" : "dismissalConfirmationDialog(_:shouldPresent:actions:message:)"
}
-->

# dismissalConfirmationDialog(_:shouldPresent:actions:message:)

Presents a confirmation dialog upon an attempt to dismiss the window
for this view.

```
@export(implementation) nonisolated func dismissalConfirmationDialog<A, M>(_ titleResource: LocalizedStringResource, shouldPresent: Bool, @ContentBuilder actions: () -> A, @ContentBuilder message: () -> M) -> some View where A : View, M : View
```

## Parameters

`titleResource`

Text resource for the localized string that describes
the title of the dialog.

`shouldPresent`

A Boolean value that determines whether
to present the dialog upon dismissal.

`actions`

A content builder returning the dialog’s actions.

`message`

A content builder returning the message for the dialog.

## Discussion

On macOS, the dialog will be presented when attempting to dismiss the
window for this view, either through a user-initiated dismissal or a
programmatic dismiss action. On iOS, the dialog will only be presented
for a user-initiated dismissal.

For example, you could present a dialog asking to persist unsaved
changes:

```swift
struct ComposeMessage: View {
    @State private var message = Message()

    var body: some View {
        MessageEditor(message: $message)
            .dismissalConfirmationDialog(
                "Save This Message As Draft?",
                shouldPresent: message.hasUnsavedChanges
            ) {
                Button("Save") {
                    message.save()
                }
                Button("Don't Save", role: .destructive) {
                    message.discard()
                }
            } message: {
                Text(
                    """
                    This message has not been sent and contains\
                    unsaved changes.
                    """)
            }
}
```

All actions in the dialog will dismiss the dialog after the
action runs. The default button will be shown with greater prominence.
You can influence the default button by assigning it the
[`defaultAction`](/documentation/SwiftUI/KeyboardShortcut/defaultAction) keyboard shortcut.

The system may reorder the buttons based on their role and prominence.

Dismissal dialogs include a standard cancellation action by default.
If you provide a button with a role of [`cancel`](/documentation/SwiftUI/ButtonRole/cancel), that
button takes the place of the default cancellation action.

The cancellation action will always prevent the dismissal, while other
actions will allow the dismiss to proceed.

On iOS, in addition to the standard cancellation action, the dismissal
dialog also includes a standard close action by default. If you provide
a button with a role of [`destructive`](/documentation/SwiftUI/ButtonRole/destructive), that button takes the
place of the default close action. This action will immediately dismiss the
dialog and the view’s associated window.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)