Instruction 2

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Protocol Extensions

You’ve now seen how to build and use relatively complex protocols. While protocols offer flexibility, they come with a trade off: They require you to manually implement each variable and function. Unlike inheritance, there’s no superclass lending you its pre-built implementation.

Generics and Protocols

Protocols also integrate nicely with generics in Swift. With protocol extensions, you can remove the duplicated code for getDescription(). However, there’s even more room for improvement. Each type of media collection is going to be pretty similar, with the only real difference being the associated type.

See forum comments
Download course materials from Github
Previous: Demo 1 Next: Demo 2