Instruction 2

Heads up... You're reading this book for free, with parts of this chapter shown beyond this point as scrambled text.

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