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 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.