Martin Velchevski Martin Velchevski - 26 days ago 7
Swift Question

@IBDesignable fails to render class instance and crashes agent with Swift 3

I have an xib which loads perfectly well after building the project. At build-time though I get the following error:

Main.storyboard: error: IB Designables: Failed to render instance of PalitraPaletteSelector: The agent crashed

I've read a lot of answers, even cleaned the DerivedData folder to no avail. Both initializers are implemented so I don't see what I'm missing here.

Here's the code I have:

class PalitraPaletteSelector: NSStackView {

@IBOutlet var view: NSStackView!

required init?(coder: NSCoder) {
super.init(coder: coder)

override init(frame frameRect: NSRect) {
super.init(frame: frameRect)

func loadViewFromNib() {
Bundle.main.loadNibNamed("PalitraPaletteSelector", owner: self, topLevelObjects: nil)
view.frame = self.bounds



You cannot use Bundle.main in a designable view. How about using Bundle(for: type(of: self)) instead.