An alert appears onscreen either as an app-modal dialog or as a sheet attached to a document window. 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.
- macOS 10.3+
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. Normally you should create an
NSAlert object 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
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
Message text The main message of the alert. Specified with
Informative text Additional information about the alert. Specified with
Icon An optional, custom icon to display in the alert, which is used instead of the default app icon. Specified with
Response buttons By default an alert has one response button: the OK button. You can add more response buttons using the
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
NSAlert class is not designed for subclassing.