8. Protocols

Protocols are at the heart of the iOS architecture; they are first-class paradigms, right up there with classes and structs. They hold a special place because they are the backbone of design patterns such as delegates. Delegates are heavily used in iOS for notifying the programmer when application, UI, and other events happen. You can use a delegate to send a message to everyone who conforms to that protocol. When you use a protocol and all of its offerings, it is called conforming to the protocol.

Protocols themselves don’t have any implementation at all—that is, you don’t really write code in protocols that does stuff. You can use protocols as a checklist to say, “I need you to write the following methods if you want this thing ...

Get Learning Swift™ Programming 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.