From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 23,400 courses taught by industry experts.

Protocols

Protocols

“

- [Instructor] Protocols are very common in iOS development. You use them in delegation, and in many frameworks and APIs including SwiftUI and Codeable. Protocols are a skeleton of another object, either a class, a struct, or an enum. Knowing what's going on with protocols will help you understand the factory protocols and improve your own coding. If you look at the exercise files, I've created two classes, one for a RectanglePizza and one for a RoundPizza. For a pizza to be a pizza, I want it to have a size, a list of toppings, and an area computation. So I created a Pizza protocol, which requires a class that adopts it to those things. The size and toppings are variables, and I set those variables like any other variable, then add if it's a mandatory getter or setter. It must be a getter, but it is not mandatory to have a setter like I did here with length. I can require a method by putting a method declaration like I…

Contents