扩展中的声明无法覆盖Swift 4中的错误 [英] Declarations in extensions cannot override yet error in Swift 4
问题描述
我有一个扩展名:
public extension UIWindow {
override public func topMostController()->UIViewController? { ... }
}
但我的 topMostController
我收到下一个错误:
but for my topMostController
I get the next error:
Declarations in extensions cannot override yet error
它适用于Swift 3.1,但对于Swift 4,我收到此错误。怎么修好?他们在Swift 4中有什么变化?
It works well for Swift 3.1, but for Swift 4 I get this error. How can it be fixed? What did they change in Swift 4?
推荐答案
如果你做基础实现它会工作 @objc
。有关内部结构的详细说明,请参见 Hamish的答案。
It will work if you make the base implementation @objc
. See Hamish's answer for a detailed explanation about the internals.
在扩展中声明的重写方法有点难以正确执行。 Objective-C支持它,但它并不是绝对安全的。斯威夫特的目标是做得更好。该提案尚未完成。
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.
提案的当前版本这里。
这篇关于扩展中的声明无法覆盖Swift 4中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!