Modal Windows

When a sheet is active, the user is prevented from interacting with the window from which it is presented. Modal windows are similar, except that they are presented independently of the other windows and they block user input for the rest of the application.

To present a window modally, use the runModalForWindow(_:) method on NSApplication:

f​u​n​c​ ​s​h​o​w​M​o​d​a​l​W​i​n​d​o​w​(​)​ ​{​ ​ ​ ​ ​l​e​t​ ​w​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​ ​=​ ​C​r​i​t​i​c​a​l​W​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​(​)​ ​ ​ ​ ​l​e​t​ ​a​p​p​ ​=​ ​N​S​A​p​p​l​i​c​a​t​i​o​n​.​s​h​a​r​e​d​A​p​p​l​i​c​a​t​i​o​n​(​)​ ​ ​ ​ ​l​e​t​ ​r​e​t​u​r​n​C​o​d​e​ ​=​ ​a​p​p​.​r​u​n​M​o​d​a​l​F​o​r​W​i​n​d​o​w​(​w​i​n​d​o​w​C​o​n​t​r​o​l​l​e​r​.​w​i​n​d​o​w​!​)​ ...

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.