I have an NSWindowController with several IBOutlets created in storyboard.
I want to add an NSView and fill it with some color. I need to place it at a specific position in views hierarchy.
I have tried 2 ways, no one succeeds.
First.
- include a custom view in storyboard
- connect to an IBOutlet
- in an init of controller, set the layer for the view
- Result: crash
Second
- build programmatically
- Result: I do not find where to put this code in the controller code
That's basic Cocoa, but way more painful than iOS.
For your first approach, are you able to provide information about the crash, like a crash log?
For your second approach, it is common to see initial view hierarchy setup for a window in your window controller subclass’s overridden windowDidLoad method.
For a view that just needs to display a solid color, NSBox can be used for this purpose:
let box = NSBox()
box.boxType = .custom
box.borderWidth = 0.0
box.fillColor = NSColor.systemRed