Chapter 9. Designing Applications Using MVC

New Mac and iPhone programmers seem to have a set life cycle. The early part of the learning process is getting used to Objective-C and maybe some basic memory management. But that’s just learning how to use your tools. The next step is figuring out how to arrange your classes and get them to talk to each other.

The first question new Cocoa programmers ask me when they get to this stage is: “How do I send data between classes?” There’s no magic sendDataToClass method or anything like that. Instead, you use Model-View-Controller, or, more commonly, MVC. This isn’t a class—it’s a mindset.

In a nutshell, MVC says that there are three kinds of objects: model objects, which hold raw data; view objects, which the user can see and click on; and controller objects, which keep the model and view objects in sync.

Tip

If you’re into science fiction, you can think of MVC as the force. It has no physical form, but it is interwoven into every part of Cocoa. It’s how Mac and iPhone programmers know how to structure classes.

To see how MVC works, you’re going to create a photo gallery application. This will be your biggest project so far in the book, but you can definitely handle it. Here are some of the topics you’ll learn about:

Core Data

As I described in Chapter 7, Core Data is Cocoa’s persistence framework. It’s what most Cocoa applications use to save and load the data between launches of the application. This is a fairly advanced topic, but we’re just ...

Get Cocoa and Objective-C: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.