Preparing the View Controller

The ViewController class doesn't have much to do here, but it does need to expose a reference to the NSManagedObjectContext that is maintained by the AppDelegate class.

Add the following property to the ViewController class:

  var managedContext = (NSApplication.shared().delegate          as! AppDelegate).managedObjectContext 

And believe it or not, that's all we'll be adding to the ViewController class. In fact, it's the only code we'll be adding at all in the first half of this chapter.

Get Mastering macOS Programming 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.