Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a function in my ViewController from my NSWindow?

Tags:

macos

swift

cocoa

I am using Swift and Storyboards. I can't figure out how to access my ViewController from my NSWindow. Storyboard doesn't seem to allow me to create an outlet from one to the other. I am sure there is some easy way to do this.

Edit: Why is this not possible?

enter image description here

like image 557
Fletcher Moore Avatar asked Nov 28 '25 01:11

Fletcher Moore


1 Answers

From my NSWindow I was able to access the NSViewController like so:

let controller = self.windowController()?.contentViewController as! ViewController;

where ViewController is the name of my ViewController subclass of NSViewController.

It is still not clear to me why I cannot just create an Outlet using Storyboard.

like image 81
Fletcher Moore Avatar answered Nov 29 '25 16:11

Fletcher Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!