-[NSWindowController init] is a Designated Initializer

Originator:nathaniel.chandler
Number:rdar://19171449 Date Originated:2014-12-07
Status:Open Resolved:
Product:OS X SDK Product Version:
Classification: Reproducible:
 
Summary:
NSWindowController's init method calls [self initWithWindow:].  In particular, it calls an initializer on self.  This means that -[NSWindowController init] is not a designated initializer: designated initializers are exactly those that call an initializer on super.  However, -[NSWindowController init] is NOT marked as a convenience, so it is understood by the compiler to be designated.

This results in the possibility of writing an NSWindowController subclass that with a new designated initializer that compiles (but shouldn't) and traps when instantiated.

Steps to Reproduce:
1.  Open the attached project.

Alternatively.

Alt.1.1:  Create a new project using the Cocoa Application template (with "Use Storyboard", "Create Document-Based Application", and "Use Core Data" all unchecked).
Alt.1.2:  Into AppDelegate.swift, paste the following class (outside of the definition of the AppDelegate class).

class WindowController: NSWindowController {
    init(arg: Int) {
        super.init()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

Alt.1.3.  Into AppDelegate.applicationDidFinishLaunching(_:), paste the following line:

let wc = WindowController(arg: 0)

2.  Attempt to run the app.

Expected Results:
1.  The app should fail to compile. 
2.  In Xcode, the line <<super.init()>> in WindowController.init(arg:) should be highlighted red with the error message <<Must call a designated initializer of the superclass 'NSWindowController'>>.

Actual Results:
1.  The app compiles.
2.  When the app runs, it traps inside WindowController's implicitly generated override of init(window:).  Here is the header in the disassembly for the implicitly generated method.

NSWindowControllerInitIsDesignatedBug`NSWindowControllerInitIsDesignatedBug.WindowController.init (NSWindowControllerInitIsDesignatedBug.WindowController.Type)(window : Swift.Optional<ObjectiveC.NSWindow>) -> NSWindowControllerInitIsDesignatedBug.WindowController at AppDelegate.swift:

Version:
Latest 6.2 beta.

Notes:
The "workaround" is to call super.init(window:) (or super.init(coder:)) from the subclass' DI.  This is actually the right thing to do.  The compiler should enforce this.  It will enforce it when -[NSWindowController init] is properly tagged as convenience.

Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!