0

I’ve used Xcode 6.3 to create a very simple Swift Mac application. It is not a document-based app. My app has one NSViewController, and it loads, opens and runs as expected. However, now I need to use the Application menu, and I don’t see the proper way for my NSViewController to communicate with the NSApplicationDelegate or the NSApplication itself.

I am looking for some chain of properties or methods I can call from my NSViewController, after it has loaded, but before it is displayed.

Charlweed
  • 1,517
  • 2
  • 14
  • 22
  • Is it the global function NSApp? Seems like it... Ah, the magic of finding the answer right after posting on stackoverflow. – Charlweed Apr 26 '15 at 17:56

1 Answers1

0

Try

override func viewDidLoad() {
    super.viewDidLoad()
    let myApplication = NSApp as! NSApplication
    let myAppDelegate = myApplication.delegate as! AppDelegate
}

Works as expected within NSViewController instance.

Charlweed
  • 1,517
  • 2
  • 14
  • 22