O'Reilly logo

Swift Quick Syntax Reference by Matthew Campbell

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

Chapter    47

Delegation

Delegation is a design pattern where one object asks another object for help. Protocols (Chapter 46) are an important part of delegation because protocols define how an object will be helped.

Delegation works by defining a protocol that will list all the methods and properties an object will need help with. Another object, known as the delegate, will provide the help needed by adopting and implementing the protocol. Objects ask for help by sending messages to their delegates.

To demonstrate delegation, imagine that you are working on a project management application and you’ve defined two classes: Project and Task. A Project instance manages a list of Task instances (see Listing 47-1).

Listing 47-1. Project Manager Classes ...

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