ios - Cannot assign Generic value to protocol associatedType variable in an extension -
i have been struggling mind problem
i trying create bindings structure on swift, bind viewmodels , controllers in easy way. have created protocol defines variable stored on controller.
protocol dva_movver_viewcontrollerprotocoldelegate { associatedtype delegatetype : dva_movver_viewmodelprotocol var dva_viewmodeldelegate : delegatetype? { set } }
as can see, variable restricted fulfill protocol, one:
protocol dva_movver_viewcontrollerprotocol { func dva_tellviewmodel() // other methods }
i want controller classes implement variable, can stored variable. cannot accomplish using extension.
so, have extension second protocol implement bindings , create common method bind variable controller
extension dva_movver_viewcontrollerprotocol self:dva_movver_viewcontrollerprotocoldelegate { mutating func dva_bindviewmodel<t:dva_movver_viewmodelprotocol>(parameter:t) { typealias delegatetype = t self.dva_viewmodeldelegate = parameter } ... // rest of dva_movver_viewcontrollerprotocol methods }
and here got stuck. compiler says “cannot assign value of type 't' type '_?’”. assume might because cannot resolve parameter type @ compile time, have no idea how solve this...
as stated @rbarbera, type erasure way go in cases:
Comments
Post a Comment