O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required