<!--
{
  "availability" : [
    "iOS: 13.0.0 - 27.0.0",
    "iPadOS: 13.0.0 - 27.0.0",
    "macCatalyst: 13.0.0 - 27.0.0",
    "macOS: 10.15.0 - 27.0.0",
    "tvOS: 13.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 6.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Alert",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5AlertV"
  },
  "title" : "Alert"
}
-->

# Alert

A representation of an alert presentation.

```
struct Alert
```

## Overview

Use an alert when you want the user to act in response to the state of the
app or system. If you want the user to make a choice in response to
their action, use an [`ActionSheet`](/documentation/SwiftUI/ActionSheet) instead.

You show an alert by using the [`alert(isPresented:content:)`](/documentation/SwiftUI/View/alert(isPresented:content:)) view
modifier to create an alert, which then appears whenever the bound
`isPresented` value is `true`. The `content` closure you provide to this
modifer produces a customized instance of the `Alert` type.

In the following example, a button presents a simple alert when
tapped, by updating a local `showAlert` property that binds to the alert.

```
@State private var showAlert = false
var body: some View {
    Button("Tap to show alert") {
        showAlert = true
    }
    .alert(isPresented: $showAlert) {
        Alert(
            title: Text("Current Location Not Available"),
            message: Text("Your current location can’t be " +
                            "determined at this time.")
        )
    }
}
```

![A default alert dialog with the title Current Location Not Available in bold text, the message your current location can’t be determined at this time in smaller text, and a default OK button.](images/com.apple.SwiftUI/SwiftUI-Alert-OK@2x.png)

To customize the alert, add instances of the [`Alert.Button`](/documentation/SwiftUI/Alert/Button) type, which
provides standardized buttons for common tasks like canceling and performing
destructive actions. The following example uses two buttons: a default
button labeled “Try Again” that calls a `saveWorkoutData` method,
and a “Delete” button that calls a destructive `deleteWorkoutData` method.

```
@State private var showAlert = false
var body: some View {
    Button("Tap to show alert") {
        showAlert = true
    }
    .alert(isPresented: $showAlert) {
        Alert(
            title: Text("Unable to Save Workout Data"),
            message: Text("The connection to the server was lost."),
            primaryButton: .default(
                Text("Try Again"),
                action: saveWorkoutData
            ),
            secondaryButton: .destructive(
                Text("Delete"),
                action: deleteWorkoutData
            )
        )
    }
}
```

![An alert dialog with the title, Unable to Save Workout Data in bold text, and](images/com.apple.SwiftUI/SwiftUI-Alert-default-and-destructive@2x.png)

The alert handles its own dismissal when the user taps one of the buttons in the alert, by setting
the bound `isPresented` value back to `false`.

## Topics

### Creating an alert

[`init(title:message:dismissButton:)`](/documentation/SwiftUI/Alert/init(title:message:dismissButton:))

Creates an alert with one button.

[`init(title:message:primaryButton:secondaryButton:)`](/documentation/SwiftUI/Alert/init(title:message:primaryButton:secondaryButton:))

Creates an alert with two buttons.

[`sideBySideButtons(title:message:primaryButton:secondaryButton:)`](/documentation/SwiftUI/Alert/sideBySideButtons(title:message:primaryButton:secondaryButton:))

Creates a side by side button alert.

### Specifying the button type

[`Alert.Button`](/documentation/SwiftUI/Alert/Button)

A button that represents an operation of an alert presentation.



---

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)