<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/alert(_:isPresented:actions:)-2gsoj",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE5alert_11isPresented7actionsQrAA4TextV_AA7BindingVySbGqd__yXEtAaBRd__lF"
  },
  "title" : "alert(_:isPresented:actions:)"
}
-->

# alert(_:isPresented:actions:)

Presents an alert when a given condition is true, using a text view for
the title.

```
nonisolated func alert<A>(_ title: Text, isPresented: Binding<Bool>, @ContentBuilder actions: () -> A) -> some View where A : View
```

## Parameters

`title`

The title of the alert.

`isPresented`

A binding to a Boolean value that determines whether to
present the alert. When the user presses or taps one of the alert’s
actions, the system sets this value to `false` and dismisses.

`actions`

A `ContentBuilder` returning the alert’s actions.

## Discussion

In the example below, a login form conditionally presents an alert by
setting the `didFail` state variable. When the form sets the value to
to `true`, the system displays an alert with an “OK” action.

```
struct Login: View {
    @State private var didFail = false
    let alertTitle: String = "Login failed."

    var body: some View {
        LoginForm(didFail: $didFail)
            .alert(
                Text(alertTitle),
                isPresented: $didFail
            ) {
                Button("OK") {
                    // Handle the acknowledgement.
                }
            }
    }
}
```

All actions in an alert dismiss the alert after the action runs.
The default button is shown with greater prominence. You can
influence the default button by assigning it the
`KeyboardShortcut/defaultAction` keyboard shortcut.

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

If no actions are present, the system includes a standard “OK”
action. No default cancel action is provided. If you want to show a
cancel action, use a button with a role of `ButtonRole/cancel`.

On iOS, tvOS, and watchOS, alerts only support controls with labels that
are `Text`. Passing any other type of view results in the content
being omitted.

---

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)