Exchanging Data Using a Protocol

One common use of protocols is to exchange data. The editor, or requestor, needs information, and the delegate provides and perhaps updates it. In this section, you design a protocol.

In this case, your car editor needs to know both the car object and number. The add/view scene, or delegate, needs to be informed when the car is changed so you can update the display. That makes three methods for the protocol:

Image carToEdit returns the car object to edit.

Image carNumber returns the number (not the index) of the edited car. ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.