Chapter 12. Protocol extensions

This chapter covers

  • Flexibly modeling data with protocols instead of subclasses
  • Adding default behavior with protocol extensions
  • Extending regular types with protocols
  • Working with protocol inheritance and default implementations
  • Applying protocol composition for highly flexible code
  • Showing how Swift prioritizes method calls
  • Extending types containing associated types
  • Extending vital protocols, such as Sequence and Collection

Previous chapters have shown how to work with protocols, associated types, and generics. To improve your abstract protocol game, this chapter sheds some light on protocol extensions. To some, being able to extend a protocol is the most significant feature of Swift, as you’ll see ...

Get Swift in Depth now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.