---
title: Alert
description: Presents an alert.
---

Presents an alert.

Use this to configure an alert presented modally or as a sheet. After configuring the alert, call presentAlert() or presentSheet() to present the alert.
The two presentations methods will return a value which carries the index of the action that was selected when fulfilled.

## Properties

### message

Detailed message displayed in the alert.

```typescript
message: string
```

### title

Title displayed in the alert. Usually a short string.

```typescript
title: string
```

## Methods

<span id="-new-alert" class="api-anchor"></span>

### new Alert()

Constructs a new alert.

```typescript
new Alert()
```

<span id="-addaction" class="api-anchor"></span>

### addAction(title)

Adds an action to the alert.

```typescript
addAction(title: string)
```

Adds an action button to the alert. To check if an action was selected, you should use the first parameter provided when the promise returned by presentAlert() and presentSheet() is resolved.

#### Parameters

**`title` `string`**

Title of the action.

<span id="-addcancelaction" class="api-anchor"></span>

### addCancelAction(title)

Adds a cancel action to the alert.

```typescript
addCancelAction(title: string)
```

Adds a cancel action to the alert. When a cancel action is selected, the index provided by presentAlert() or presentSheet() will always be -1. Please note that when running on the iPad and presenting using presentSheet(), the action will not be shown in the list of actions. The operation is cancelled by tapping outside the sheet.

An alert can only contain a single cancel action. Attempting to add more cancel actions will remove any previously added cancel actions.

#### Parameters

**`title` `string`**

Title of the action.

<span id="-adddestructiveaction" class="api-anchor"></span>

### addDestructiveAction(title)

Adds a destructive action to the alert.

```typescript
addDestructiveAction(title: string)
```

Destructive action titles have a red text color, signaling that the action may modify or delete data.

#### Parameters

**`title` `string`**

Title of the action.

<span id="-addsecuretextfield" class="api-anchor"></span>

### addSecureTextField(placeholder, text)

Adds a secure text field prompting for user input.

```typescript
addSecureTextField(placeholder: string, text: string): TextField
```

Adds a secure text field to the alert controller prompting for user input. Values entered into a secure text field will be hidden behind dots. Retrieve the value for the text field using textFieldValue() and supply the index of the text field. Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

#### Parameters

**`placeholder` `string`**

Optional placeholder that will be displayed when the text field is empty.

**`text` `string`**

Optional default value for the text field.

#### Return value

**`TextField`**

Text field added to the alert.

<span id="-addtextfield" class="api-anchor"></span>

### addTextField(placeholder, text)

Adds a text field prompting for user input.

```typescript
addTextField(placeholder: string, text: string): TextField
```

Adds a text field to the alert controller prompting for user input. Retrieve the value for the text field using textFieldValue() and supply the index of the text field. Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

Text fields are not supported when using the sheet presentation.

#### Parameters

**`placeholder` `string`**

Optional placeholder that will be displayed when the text field is empty.

**`text` `string`**

Optional default value for the text field.

#### Return value

**`TextField`**

Text field added to the alert.

<span id="-present" class="api-anchor"></span>

### present()

Presents the alert modally.

```typescript
present(): Promise<number>
```

This is a shorthand for presentAlert().

#### Return value

**`Promise<number>`**

A promise carrying the selected action index when fulfilled.

<span id="-presentalert" class="api-anchor"></span>

### presentAlert()

Presents the alert modally.

```typescript
presentAlert(): Promise<number>
```

#### Return value

**`Promise<number>`**

A promise carrying the selected action index when fulfilled.

<span id="-presentsheet" class="api-anchor"></span>

### presentSheet()

Presents the alert as a sheet.

```typescript
presentSheet(): Promise<number>
```

#### Return value

**`Promise<number>`**

A promise carrying the selected action index when fulfilled.

<span id="-textfieldvalue" class="api-anchor"></span>

### textFieldValue(index)

Retrieves value of a text field.

```typescript
textFieldValue(index: number): string
```

Retrieves the value of a text field added using addTextField() or addSecureTextField(). Indices for text fields are assigned in the same order as they are added to the alert starting at 0.

#### Parameters

**`index` `number`**

Index of text field to retrieve for value.

#### Return value

**`string`**

Value of the text field at the specified index.