swift - How to conform to protocol using subclass -
say have protocol
protocol a: class { func configure(view: uiview) }
now want conform protocol, using uilabel
subclass of uiview
final class b: { init() {} func configure(view: uilabel) { } }
but errors
type b not conform protocol a
it seems swift needs same type stated in protocol. works
final class b: { init() {} func configure(view: uiview) { } }
but want use uilabel
, how work around this?
you use associatedtype
constrained of type uiview
.
protocol a: class { associatedtype view: uiview func configure(view: view) }
now in class b
, since uilabel
subclass of uiview
, it's fine do:
final class b: { init() {} func configure(view: uilabel) { ... } }
Comments
Post a Comment