O'Reilly logo

Cocoa® by Richard Wentk

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

mac_ch9.eps
co_bar.eps

Chapter 9: Using Cocoa Design Patterns and Advanced Messaging

mac_chbox9.eps

In This Chapter

Understanding Model-View-Controller in Cocoa

Understanding and using target-action

Using Key-Value Coding

Using Key-Value Observing

Working with notifications and errors

It's traditional in a Cocoa book to mention design patterns and features such as Model-View-Controller (MVC), target-action, Key-Value Coding (KVC), and Key-Value Observing (KVO).

Apple's documentation mystifies these design patterns and makes them seem more difficult and complex than they really are. They're an essential part of Cocoa, and you can use them to implement impressively efficient code. But the practice can be much simpler than the theory.

Understanding Model-View-Controller

Model-View-Controller, often shortened to MVC, was introduced in Chapter 2. The outline of MVC is shown in Figure 9.1. An application is split into three elements — a store of data called a model, an interface called a view, and a controller object that passes data between them.

MVC implies, but doesn't enforce, the suggestion that model data should be kept in separate objects and perhaps in separate custom classes.

In a simple application, this seems ...

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