protocol BasePresenterProtocol : class {}protocol DashboardPresenterProtocol : BasePresenterProtocol {}final class DashboardPresenter { weak var vIEw: DashboardPresenterProtocol? init() { self.vIEw = DashboardVIEwController() } func test() { print("Hello") }}extension DashboardPresenter: DashboardVIEwProtocol { }protocol BaseVIEwProtocol : class { weak var vIEw: BasePresenterProtocol? { get set }}protocol DashboardVIEwProtocol : BaseVIEwProtocol {}class DashboardVIEwController {}extension DashboardVIEwController: DashboardPresenterProtocol { }
在上面的代码中,我在下一行收到错误
extension DashboardPresenter: DashboardVIEwProtocol { }
那,DashboardPresenter没有确认协议DashboardVIEwProtocol,但我已经声明了弱var视图:DashboardPresenterProtocol?在DashboardPresenter中.虽然我已经宣布了
为什么我收到此错误?请让我知道我在这段代码中做错了什么.
解决方法 您无法实现BasePresenterProtocol类型的读写属性要求?具有DashboardPresenterProtocol类型的属性?考虑如果可能会发生什么,并将DashboardPresenter的实例向上转换为DashboardVIEwProtocol.您可以将符合BasePresenterProtocol的任何内容分配给DashboardPresenterProtocol类型的属性吗? – 这将是非法的.
出于这个原因,读写属性要求必须是不变的(尽管值得注意的是,只读的属性要求应该能够协变 – but this currently isn’t supported).
总结以上是内存溢出为你收集整理的Swift协议继承和协议一致性问题全部内容,希望文章能够帮你解决Swift协议继承和协议一致性问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)