<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAlertController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIAlertController"
  },
  "title" : "UIAlertController"
}
-->

# UIAlertController

An object that displays an alert message.

```
@MainActor class UIAlertController
```

## Overview

Use this class to configure alerts and action sheets with the message that you want to display and the actions from which to choose. After configuring the alert controller with the actions and style you want, present it using the [`present(_:animated:completion:)`](/documentation/UIKit/UIViewController/present(_:animated:completion:)) method. UIKit displays alerts and action sheets modally over your app’s content.

In addition to displaying a message to a user, you can associate actions with your alert controller to give people a way to respond. For each action you add using the [`addAction(_:)`](/documentation/UIKit/UIAlertController/addAction(_:)) method, the alert controller configures a button with the action details. When a person taps that action, the alert controller executes the block you provided when creating the action object. The following code shows how to configure an alert with a single action.

```objc
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"
                               message:@"This is an alert."
                               preferredStyle:UIAlertControllerStyleAlert];
 
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
   handler:^(UIAlertAction * action) {}];
 
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
```

When configuring an alert with the [`UIAlertController.Style.alert`](/documentation/UIKit/UIAlertController/Style/alert) style, you can also add text fields to the alert interface. The alert controller lets you provide a block for configuring your text fields prior to display. The alert controller maintains a reference to each text field so that you can access its value later.

> Important:
> The ``doc://com.apple.uikit/documentation/UIKit/UIAlertController`` class is intended to be used as-is and doesn’t support subclassing. The view hierarchy for this class is private and must not be modified.

## Topics

### Creating an alert controller

[`init(title:message:preferredStyle:)`](/documentation/UIKit/UIAlertController/init(title:message:preferredStyle:))

Creates and returns a view controller for displaying an alert.

### Configuring the alert

[`title`](/documentation/UIKit/UIAlertController/title)

The title of the alert.

[`message`](/documentation/UIKit/UIAlertController/message)

Descriptive text that provides more details about the reason for the alert.

[`preferredStyle`](/documentation/UIKit/UIAlertController/preferredStyle)

The style of the alert controller.

[`UIAlertController.Style`](/documentation/UIKit/UIAlertController/Style)

Constants indicating the type of alert to display.

### Configuring the user actions

[`addAction(_:)`](/documentation/UIKit/UIAlertController/addAction(_:))

Attaches an action object to the alert or action sheet.

[`actions`](/documentation/UIKit/UIAlertController/actions)

The actions that the user can take in response to the alert or action sheet.

[`preferredAction`](/documentation/UIKit/UIAlertController/preferredAction)

The preferred action for the user to take from an alert.

### Configuring text fields

[`addTextField(configurationHandler:)`](/documentation/UIKit/UIAlertController/addTextField(configurationHandler:))

Adds a text field to an alert.

[`textFields`](/documentation/UIKit/UIAlertController/textFields)

The array of text fields displayed by the alert.

### Configuring alert severity

[`severity`](/documentation/UIKit/UIAlertController/severity)

Indicates the severity of the alert.

[`UIAlertControllerSeverity`](/documentation/UIKit/UIAlertControllerSeverity)

Constants for specifying the severity of an alert in apps built with Mac Catalyst.



---

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)