April 2015
Intermediate to advanced
556 pages
17h 47m
English
Cocoa’s sheet and modal window presentation APIs are very flexible: you can supply your own Int as the modal response or return code. Unfortunately this leaves room for error and confusion since it can be unclear how to map an Int back to something meaningful. (Did the user click Accept or Cancel?) By tucking the sheet or modal window API usage into your window controller you can add some safety and grace to your use of them.
Consider the following code for the fictional CriticalWindowController:
class CriticalWindowController: NSWindowController { enum ModalResult: Int { case Accept case Cancel } func runModal() -> ModalResult { let app = NSApplication.sharedApplication() let returnCode = app.runModalForWindow(window!) ...