O'Reilly logo
  • Bram Havers thinks this is interesting:

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

From

Cover of Mastering macOS Programming

Note

In later Swift versions this needs to be: @objc let managedContext = (NSApplication.shared().delegate as! AppDelegate).persistentContainer.viewContext See: https://stackoverflow.com/questions/39200385/managedobjectcontext-in-swift-3 and https://stackoverflow.com/questions/46346518/how-do-i-bind-my-array-controller-to-my-core-data-model