Skip to Content
iOS 7 Programming Fundamentals
book

iOS 7 Programming Fundamentals

by Matt Neuburg
October 2013
Beginner content levelBeginner
422 pages
12h 35m
English
O'Reilly Media, Inc.
Content preview from iOS 7 Programming Fundamentals

Chapter 13. 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. The problem is essentially one of architecture. 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 one object to be able to communicate with another.

The problem of communication often comes down to one object being able to see another: 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.

One obvious solution is an instance variable of Manny whose value is Jack. This is appropriate particularly when Manny and Jack share certain responsibilities or supplement one another’s functionality. The application object and its delegate, a table view and its data source, a view controller and the view that it controls — these are cases where the former must have an instance variable pointing at the latter.

This does not necessarily imply that Manny needs to assert ownership of Jack (as a matter of memory management policy, Chapter 12). An object does not typically retain its delegate or its data source; similarly, an object that implements the target–action pattern, such as a UIControl, does not retain its target. But then Manny ...

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 7 Programming Cookbook

iOS 7 Programming Cookbook

Vandad Nahavandipoor
Programming iOS 11

Programming iOS 11

Matt Neuburg
Programming iOS 12

Programming iOS 12

Matt Neuburg

Publisher Resources

ISBN: 9781491946039Errata PageSupplemental Content