19 Protocols

In Chapter 16, you learned about using access controls to hide information. Hiding information is a form of encapsulation, which allows you to design your software in such a way that you can change one part without affecting the rest. Swift also supports another form of encapsulation: a protocol, which allows you to specify and work with the interface of a type without knowing the type itself. An interface is a set of properties and methods that a type provides.

Protocols are a more abstract concept than many of the topics you have learned about so far. To get a handle on protocols and how they work, you will create a function that formats data into a table that looks like a simple spreadsheet. Next, you will use ...

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.