Add a view defined in a xib file in a Window in the soryboard using Xcode & Swift

434 views Asked by At

I have a window in the storyboard and a box in defined a xib file. I would like to see the box appearing on the window as soon as the app launches.

The box is also defined by a custom cocoa class that I created and I associated to the xib file. The class is called Box.

Why does the code in the picture doesn't show the box in the window? The code is in the NSViewController of the window. Thank you

1

There are 1 answers

2
Quentin Hayot On BEST ANSWER

Try to replace window.addSubview(box) with self.view.addSubview(box).
You need to display your view as a subview of your root view controller.