O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

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

Setting Up the View Controller

The template creates a few Swift files and a file called Main.storyboard, which you will get to in a moment. 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)

import Cocoa

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

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

    override var representedObject: Any? {
        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 ...

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