Skip to Content
iOS 15 Programming Fundamentals with Swift
book

iOS 15 Programming Fundamentals with Swift

by Matt Neuburg
October 2021
Intermediate to advanced content levelIntermediate to advanced
786 pages
21h 17m
English
O'Reilly Media, Inc.
Book available
Content preview from iOS 15 Programming Fundamentals with Swift

Chapter 14. Communication Between Objects

As soon as an app grows to more than a few objects, puzzling questions can arise about how to send a message or communicate data between one object and another. It may require some planning to construct your code so that all the pieces fit together and information can be shared as needed at the right moment. This chapter presents some organizational considerations that will help you arrange for coherent communication between objects.

Visibility Through an Instance Property

One object’s ability to communicate with another often comes down to one object being able to see another. If the object Manny needs to be able to find the object Jack repeatedly and reliably over the long term so as to be able to send Jack messages, Manny will presumably need a way of seeing Jack in the first place.

One obvious solution is an instance property of Manny whose value is Jack. An instance property is appropriate particularly when Manny and Jack share certain responsibilities or supplement one another’s functionality. Here are some commonly occurring cases where one object needs to have an instance property pointing at another:

  • The application object and its delegate

  • A table view and its data source

  • A view controller and the view that it controls

Manny may have an instance property pointing to Jack, but this does not necessarily imply that Manny needs to assert ownership of Jack as a matter of memory management policy (see Chapter 13). Here are ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

iOS 15 Programming for Beginners - Sixth Edition

iOS 15 Programming for Beginners - Sixth Edition

Ahmad Sahar, Craig Clayton
Programming iOS 14

Programming iOS 14

Matt Neuburg

Publisher Resources

ISBN: 9781098118495Supplemental ContentErrata Page