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 the O’Reilly learning platform.

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