Swift Protocol inheritance and protocol conformance issue -
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? { set } } protocol dashboardviewprotocol : baseviewprotocol { } class dashboardviewcontroller { } extension dashboardviewcontroller: dashboardpresenterprotocol { }
in above code, error @ following line
extension dashboardpresenter: dashboardviewprotocol { }
that, dashboardpresenter
doesn't confirm protocol dashboardviewprotocol
, have declared weak var view: dashboardpresenterprotocol?
in dashboardpresenter
. although have declared
why getting error ? please let me know doing wrong in code.
you cannot implement read-write property requirement of type basepresenterprotocol?
property of type dashboardpresenterprotocol?
.
think happen if were possible, , upcast instance of dashboardpresenter
dashboardviewprotocol
. able assign conforms basepresenterprotocol
property of type dashboardpresenterprotocol?
– illegal.
for reason, read-write property requirement has invariant (although it's worth noting readable-only property requirement should able covariant – but isn't supported).
although in case, protocols don't conform themselves, cannot use dashboardpresenterprotocol?
type conforms basepresenterprotocol?
.
Comments
Post a Comment