From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adopting multiple protocols

Adopting multiple protocols

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Adopting multiple protocols

- [Instructor] So far, we've worked with types that adopted a single protocol. With protocol composition we can create types that conform to multiple protocols. Protocol composition is one of the pillars of the protocol oriented programming paradigm. Swift, like many other programming languages doesn't allow multiple inheritance for classes. However, any type can adapt to multiple protocols. Why is this so important? By conforming to multiple protocols, we can ensure that our types implement the requirements they really need. Instead of inheriting unnecessary noise from a class hierarchy, our types can adopt the protocols that are needed for their proper functionality. All right, let's see how it works. You can follow along with me by opening the starter playground project from the exercise files folder. Chapter one, 0107, begin. First, I create a structure called my data. Let's assume that it has to support…

Contents