0

I created a storyboard project using Xcode (9.2).

I then created a custom subclass of NSWindow and used the storyboard editor to set that as the class for my window.

class CustomWindow: NSWindow {

    init() {
        super.init(contentRect: NSRect.zero, styleMask: .borderless, backing: .buffered, defer: true)
        self.setFrame(NSScreen.screens[0].visibleFrame, display: false)
    }

}

[Edited for clarity]

The project complies ok, but upon running throws up this error on the line containing the super.init() call:

Fatal error: Use of unimplemented initializer 'init(contentRect:styleMask:backing:defer:)'

Wouldn't the super class (NSWindow) already contain that implementation?

What am I missing?

Himanshu P
  • 8,305
  • 5
  • 35
  • 45

1 Answers1

1

If you use it in the storyboard then you need to implement the init method you get an error about since it is the designated one for NSWindow.

See this question Fatal error: use of unimplemented initializer 'init(coder:)' for class for example

Joakim Danielson
  • 29,280
  • 4
  • 14
  • 35
  • But the super.init would be called on the super class NSWindow -- my class doesn't need that specific init() method, and I don't understand why I should implement it. – Himanshu P Mar 14 '18 at 10:32
  • Because the storyboard is using the designated initialiser for the NSWindow class to create your window – Joakim Danielson Mar 14 '18 at 10:36
  • ok, I see. shouldn't it be a compile time error in that case? – Himanshu P Mar 14 '18 at 10:38
  • also, i've edited the question to indicate that the run-time error occurs on the call to super.init()... in which case your comment doesn't seem to add up? – Himanshu P Mar 14 '18 at 10:39
  • I guess the compiler can't know that you're using the storyboard to instantiate your window – Joakim Danielson Mar 14 '18 at 10:39
  • but the run-time error occurs on the call to super.init()... not in some storyboard related code. – Himanshu P Mar 14 '18 at 10:41
  • The window will get created for you so this isn't about any of your storyboard related code. It is my understanding that you need to override the designated initialiser for this to work. Have you tried to implement an init(contentRect:styleMask:backing:defer:) method and seen what happens, you can stil use your own values when calling super.init(...) – Joakim Danielson Mar 14 '18 at 10:55