O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheriting and adding associated types in protocols

Now, we want to declare a PartyWithDeeJayProtocol protocol and make the generic PartyWithDeeJay<AnimalElement, DeeJayElement> class conform to this new protocol. We will make this protocol inherit from the previously created PartyProtocol that defined a MemberType associated type. Thus, the PartyWithDeeJayProtocol protocol will inherit this associated type. We have to specify another associated type that will be specified during the protocol implementation, that is, when we declare the class that conforms to the new protocol. The following lines show the declaration of the PartyWithDeeJayProtocol protocol that inherits from the PartyProtocol protocol. We must declare the protocol before the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required