以下代码抛出错误
protocol WhatA: AnyObject {
func doThat()
}
protocol WhatB: WhatA {
func doThis()
}
class SomethingA {
weak var delegate: WhatA?
}
class SomethingB: SomethingA {
weak var delegate: WhatB?
}
Run Code Online (Sandbox Code Playgroud)
类型为“ WhatB?”的属性“委托” 无法覆盖类型为“ WhatA?”的属性
UIKit在以下方面没有问题
open class UIScrollView : UIView, NSCoding, UIFocusItemScrollableContainer {
weak open var delegate: UIScrollViewDelegate?
}
open class UITableView : UIScrollView, NSCoding, UIDataSourceTranslating {
weak open var delegate: UITableViewDelegate?
}
Run Code Online (Sandbox Code Playgroud)
为什么这在UIKit中起作用?这个问题的公认答案表明这是不可能的。