Delegation

You can also think of a protocol as an interface definition between two classes. The class that defines the protocol can be thought of as delegating the work defined by the methods in the protocol to the class that implements them. In that way, the class can be defined to be more general, with specific actions taken by the delegate class in response to certain events or to define specific parameters. Cocoa and iOS rely heavily on this concept of delegation. For example, when you set up a table on the iPhone’s display, you’ll use the UITableView class. But that class doesn’t know the title of the table, how many sections or rows it contains, or what to put in each row (cell) of the table. So, it delegates that responsibility to you ...

Get Programming in Objective-C, Sixth Edition 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.