Skip to content

Instantly share code, notes, and snippets.

@wildthink
Created April 2, 2017 14:58
Show Gist options
  • Save wildthink/c2d7ec3d0775419e1e598479e31d1845 to your computer and use it in GitHub Desktop.
Save wildthink/c2d7ec3d0775419e1e598479e31d1845 to your computer and use it in GitHub Desktop.
NSDocument ViewController Hooks
extension NSViewController {
var document: AnyObject? {
if let target = self.parent, target.responds (to: #selector(getter: self.document)) {
return target.perform(#selector(getter: self.document)) as AnyObject?
}
return self.view.window?.windowController?.document
}
var managedObjectContext: NSManagedObjectContext? {
return (document as? NSPersistentDocument)?.managedObjectContext
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment