O'Reilly logo

Programming iOS 4 by Matt Neuburg

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 13. Data Communication

As soon as an app grows to more than a few objects, things can become confusing. Beginners are sometimes puzzled about how to communicate data between one piece of code (one object, really) and another. The problem is essentially one of architecture. Constructing your code so that all the pieces fit together and key information can be shared is something of an art. But it isn’t difficult. This chapter presents some general considerations that may provide the needed clue.

Model–View–Controller

In Apple’s documentation and online, you will find references to the term model–view–controller, or MVC. This refers to an architectural goal of maintaining a distinction between three functional aspects of a program that displays information to the user and permits the user to alter that information. The whole notion goes back to the days of Smalltalk, and much has been written about it since then, but informally, here’s what the terms mean:

Model
The data and its management (often referred to as the program’s “business logic,” the hard-core stuff that the program is really all about).
View
What the user sees and interacts with.
Controller
The mediation between the model and the view.

Consider, for example, a game where the current score is displayed to the user:

  • A UILabel that shows the user the current score for the game in progress is view; it is effectively nothing but a pixel-maker, and its business is to know how to draw itself. The knowledge of what ...

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