Setting Up the View Controller

The template creates a few Swift files and a file called Main.storyboard, which you will get to momentarily. First, open ViewController.swift. Begin by removing the overridden functions the template provided for you, as you will not need them for this app.

Listing 26.1  Cleaning out template code (ViewController.swift)

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }

}

Note that the ViewController class is a subclass of NSViewController. As the name suggests, a view controller manages the user interface and ...

Get Swift Programming: 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.