---
title: "alert(_:isPresented:actions:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/alert(_:ispresented:actions:)"
---

# alert(_:isPresented:actions:)

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

## Declaration

```swift
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 doc://com.apple.SwiftUI/documentation/SwiftUI/ContentBuilder returning the alert’s actions.

## Discussion

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 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 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.

## See Also

### Presenting an alert

- [AlertScene](swiftui/alertscene.md)
- [alert(_:isPresented:presenting:actions:)](swiftui/view/alert(_:ispresented:presenting:actions:).md)
- [alert(_:item:actions:)](swiftui/view/alert(_:item:actions:).md)
- [alert(error:actions:)](swiftui/view/alert(error:actions:).md)
- [alert(isPresented:error:actions:)](swiftui/view/alert(ispresented:error:actions:).md)
- [alert(_:isPresented:actions:message:)](swiftui/view/alert(_:ispresented:actions:message:).md)
- [alert(_:isPresented:presenting:actions:message:)](swiftui/view/alert(_:ispresented:presenting:actions:message:).md)
- [alert(_:item:actions:message:)](swiftui/view/alert(_:item:actions:message:).md)
- [alert(error:actions:message:)](swiftui/view/alert(error:actions:message:).md)
- [alert(isPresented:error:actions:message:)](swiftui/view/alert(ispresented:error:actions:message:).md)
