Swift: declaration 'description' cannot override more than one superclass declaration

前端 未结 4 1696
深忆病人
深忆病人 2021-02-08 10:07

I have a structure of inheritance similar to the one below. I\'m adopting the Printable protocol and diligently override description property. I have encountered a bizarre error

4条回答
  •  旧巷少年郎
    2021-02-08 10:29

    I had the same problem with SKTiled when overriding SKTiledScene. In my situation I wanted to override a mouse event for OS X.

    The error was as follows:

    Declaration 'mouseUp(with:)' cannot override more than one superclass declaration
    

    The problem here is that the mouse events are declared in a class extension:

    #if os(macOS)
    extension SKTiledScene {
    
        override open func mouseDown(with event: NSEvent) {}
    
        override open func mouseMoved(with event: NSEvent) {
            guard let cameraNode = cameraNode else { return }
            cameraNode.mouseMoved(with: event)
        }
        override open func mouseUp(with event: NSEvent) {}
        override open func mouseEntered(with event: NSEvent) {}
        override open func mouseExited(with event: NSEvent) {}
    
        override open func scrollWheel(with event: NSEvent) {
            guard let cameraNode = cameraNode else { return }
            cameraNode.scrollWheel(with: event)
        }
    }
    #endif
    

    I could solve my issue to override the method in my own SKTiledScene subclass by re-implementing the extension:

    extension SKTiledScene {
        open override func mouseUp(with event: NSEvent) {
            try! SceneManager.shared.transitionToScene(MainMenuScene.self, withAnimation: .fade)
        }
    }
    

    I do wonder if I can be sure my extension is always loaded instead of the one from the SKTiled framework, but it seems to work well for now.

提交回复
热议问题