Declarations in extensions cannot override yet error in Swift 4

后端 未结 3 1214
情歌与酒
情歌与酒 2020-12-29 19:44

I have an extension:

public extension UIWindow {
    override public func topMostController()->UIViewController? { ... }
}

but for my

3条回答
  •  [愿得一人]
    2020-12-29 19:59

    It will work if you make the base implementation @objc. See Hamish's answer for a detailed explanation about the internals.

    Overriding methods declared in extensions is a bit tricky to do correctly. Objective-C supports it, but it's not absolutely safe. Swift aims to do it better. The proposal is not completed yet.

    Current version of the proposal available here.

提交回复
热议问题