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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -