---
title: NSAlert
framework: appkit
role: symbol
role_heading: Class
path: appkit/nsalert
---

# NSAlert

A modal dialog or sheet attached to a document window.

## Declaration

```swift
@MainActor class NSAlert
```

## Overview

Overview The methods of the NSAlert class allow you to specify alert level, alert text, button titles, and a custom icon should you require it. The class also lets your alerts display a help button and provides ways for apps to offer help specific to an alert. To display an alert as a sheet, call the beginSheetModal(for:completionHandler:) method; to display one as an app-modal dialog, use the runModal() method. By design, an NSAlert object is intended for a single alert—that is, an alert with a unique combination of title, buttons, and so on—that is displayed upon a particular condition. You should create an NSAlert object for each alert dialog, creating it only  when you need to display an alert, and release it when you are done. If you have a particular alert dialog that you need to show repeatedly, you can retain and reuse an instance of NSAlert for this dialog. After creating an alert using one of the alert creation methods, you can customize it further prior to displaying it by customizing its attributes. See Instance Attributes. Unless you must maintain compatibility with existing alert-processing code that uses the function-based API, you should allocate (alloc) and initialize (init) the alert object, and then set its attributes using the appropriate methods of the NSAlert class. Instance Attributes NSAlert objects have the following attributes: Type An alert’s type helps convey the importance or gravity of its message to the user. Specified with the alertStyle property. Message text The main message of the alert. Specified with messageText. Informative text Additional information about the alert. Specified with informativeText. Icon An optional, custom icon to display in the alert, which is used instead of the default app icon. Specified with icon. Help Alerts can let the user get help about them. Use helpAnchor and showsHelp. Response buttons By default an alert has one response button: the OK button. You can add more response buttons using the addButton(withTitle:) method. Suppression checkbox A suppression checkbox allows the user to suppress the display of a particular alert in subsequent occurrences of the event that triggers it. Use showsSuppressionButton. Accessory view An accessory view lets you add additional information to an alert; for example, a text field with contact information. Use accessoryView, layout(). Subclassing Notes The NSAlert class is not designed for subclassing.

## Topics

### Creating Alerts

- [init(error:)](appkit/nsalert/init(error:).md)

### Configuring Alerts

- [layout()](appkit/nsalert/layout().md)
- [alertStyle](appkit/nsalert/alertstyle.md)
- [accessoryView](appkit/nsalert/accessoryview.md)
- [showsHelp](appkit/nsalert/showshelp.md)
- [helpAnchor](appkit/nsalert/helpanchor.md)
- [delegate](appkit/nsalert/delegate.md)

### Displaying Alerts

- [runModal()](appkit/nsalert/runmodal().md)
- [beginSheetModal(for:completionHandler:)](appkit/nsalert/beginsheetmodal(for:completionhandler:).md)
- [beginSheetModal(for:modalDelegate:didEnd:contextInfo:)](appkit/nsalert/beginsheetmodal(for:modaldelegate:didend:contextinfo:).md)
- [suppressionButton](appkit/nsalert/suppressionbutton.md)
- [showsSuppressionButton](appkit/nsalert/showssuppressionbutton.md)

### Accessing Alert Text

- [informativeText](appkit/nsalert/informativetext.md)
- [messageText](appkit/nsalert/messagetext.md)

### Accessing a Custom Alert Icon

- [icon](appkit/nsalert/icon.md)

### Accessing Alert Response Buttons

- [buttons](appkit/nsalert/buttons.md)
- [addButton(withTitle:)](appkit/nsalert/addbutton(withtitle:).md)

### Getting Alert Windows

- [window](appkit/nsalert/window.md)

### Constants

- [NSAlert.Style](appkit/nsalert/style.md)
- [NSApplication.ModalResponse](appkit/nsapplication/modalresponse.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)

## See Also

### Related Documentation

- [Dialogs and Special Panels](apple-archive/documentation/Cocoa/Conceptual/Dialog.md)

### Alerts

- [NSAlertDelegate](appkit/nsalertdelegate.md)
