Circular warnings about Swift static override being final

1.2k views Asked by At

I have an NSDocumentController subclass that needs to know if it has restored any windows via the NSWindowRestoration protocol.

The particular function I'm overriding, documented here, to do this is:

override open static func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void)

As written, this function is called exactly when I'd like and works perfectly. However, I get the following warning:

Static declarations are implicitly 'final'; use 'public' instead of 'open'

This warning includes a seemingly helpful fixit, to transform that open into public. But, when I accept, I then get this error:

Overriding static method must be as accessible as the declaration it overrides

This error suggests I replace public with open.

I've opened a radar with Apple about this circular behavior. But, I'd really like to find a way to quiet this warning. Alternatively, perhaps there's another way for an NSDocumentController subclass to be informed that it has restored windows.

To reproduce this error, create a new App project with Xcode 10, and include the following code. I just threw it in after the AppDelegate declaration. By default, the project is configured with Swift 4.2 and builds for macOS 10.14.

class MyDocumentController: NSDocumentController {
    override open static func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void) {
        super.restoreWindow(withIdentifier: identifier, state: state, completionHandler: completionHandler)
    }
}
1

There are 1 answers

0
Mattie On BEST ANSWER

Thanks to Martin R above for the link to the issue in the Swift compiler. That issue also has a workaround, that does indeed fix the issue for me.

Fixing this is possible by actually using class instead of static in the override in class Y.