15 Alerts and Closures

Occasionally, you will want to warn the user about something by presenting an alert. To do this, you use the NSAlert class. NSAlert saves you the work of designing a custom user interface for a simple and common user interaction, while also providing the user with a consistent experience.

NSAlert

Figure 15.1 shows a basic modal alert:

Figure 15.1  A modal alert

A modal alert

Here is the code used to create and present that alert:

l​e​t​ ​a​l​e​r​t​ ​=​ ​N​S​A​l​e​r​t​(​)​ a​l​e​r​t​.​m​e​s​s​a​g​e​T​e​x​t​ ​=​ ​"​A​l​e​r​t​ ​m​e​s​s​a​g​e​.​"​ a​l​e​r​t​.​i​n​f​o​r​m​a​t​i​v​e​T​e​x​t​ ​=​ ​"​A​ ​m​o​r​e​ ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.