CHAPTER 23

image

Protocols

Protocols Overview

Protocols are used to define a set of methods and properties independently of a class. Any class can adopt a protocol, which means that the class implements the properties and methods defined by the protocol. In effect, protocols define a contract that classes can agree to fulfill. When a class adopts a protocol, you can be confident that the class will have implemented the properties and methods in the protocol.

Defining Protocols

To use protocols, you must start by defining the protocol. Use the @protocol keyword to start defining the protocol. You can simply include this in the same file as the class ...

Get Objective-C Quick Syntax Reference 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.