Swift is swift largely because so many standard types are structs, not classes, and Swift encourages you to create structs wherever possible. Structs don’t have inheritance to support polymorphism — they use protocols, instead. And protocols work just as well with classes, enums and other protocols — you can compose or inherit protocols, providing you with unlimited flexibility in creating a modular app architecture.
It’s hard to see just how useful protocols are until you work on a large codebase and for a long time. Everything protocols offer can be approximated in other ways, using inheritance, generics, function overloading, or copying and pasting code. By using protocols, you get clear intentions and semantics as well as protocol-guaranteed safety and ease of refactoring.
Learning Objectives
You already learned a lot about protocols from Object Oriented Programming in iOS — how to create protocols, how to extend and compose them, how they support SOLID principles, and a bit about protocols with associated types. Here’s what you’ll learn in this lesson:
Zor lo tofibe lnovyel ve olmarh e ynogibup, avjotoh ebnev bmufakeql, if emi gmixehef lohrinecoap. Ovxledo fnixox esy snferub fakqumxv uwy puw nhabe eggelj tpukajah eflikdeutr.
Doj hu tniexi a dyelihib lulh ahgofoiqej hpnu, elw sek ajb stj ni oka wbhi efijoca fusl lahudax pqwok.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.