<!--
{
  "availability" : [
    "macOS: 15.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/dialogPreventsAppTermination(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE28dialogPreventsAppTerminationyQrSbSgF"
  },
  "title" : "dialogPreventsAppTermination(_:)"
}
-->

# dialogPreventsAppTermination(_:)

Whether the alert or confirmation dialog prevents the app
from being quit/terminated by the system or app termination menu item.

```
nonisolated func dialogPreventsAppTermination(_ prevents: Bool?) -> some View
```

## Discussion

SwiftUI uses the actions passed to the above dialogs to determine
whether the dialog should block app termination by default when
presented. If all of the following are satisfied, the dialog will
not block app quit:

- There is only a single button and its role is not [`destructive`](/documentation/SwiftUI/ButtonRole/destructive)
- The [`dialogSeverity(_:)`](/documentation/SwiftUI/View/dialogSeverity(_:)) is not `DialogSeverity/critical``
- There are no [`TextField`](/documentation/SwiftUI/TextField)s

Use this modifier after a `View/alert` or `View/confirmationDialog`
to specify whether the dialog should prevent app termination.
Pass `nil` to explicitly request the automatic behavior/for the inert
version of this modifier.

```
struct ConfirmLogoutView: View {
  @State private var isConfirming = false

  var body: some View {
    Button("Logout") { isConfirming = true }
      .confirmationDialog(
        Text("Logout?"),
          isPresented: $isConfirming
        ) {
          Button("Yes") {
            // Handle logout action.
          }
        }
        .dialogPreventsAppTermination(false)
    }
}
```

---

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)