O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required