Chapter    15

Protocols

In the real world, people on official business are often required to follow strict procedures when dealing with certain situations. Law enforcement officials, for example, are required to “follow protocol” when making inquiries or collecting evidence.

In the world of object-oriented programming, it’s important to be able to define a set of behaviors that’s expected of an object in a given situation. As an example, a table view expects to be able to communicate with a data source object in order to find out what it’s required to display. This means the data source must be able to respond to the specific messages the table view might send.

Protocols define the interface—a blueprint of methods, properties, and other requirements ...

Get Learn Swift on the Mac: For OS X and iOS 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.