Chapter 9. Model Objects and Data Storage

Unless your application is a trivial one, it will need to work with data at some point. This data could be as simple as a list of high scores that the user has achieved, or as complex as a multimedia document like a presentation.

This information needs to be accessible to other parts of your application, such as the controller objects, so that work can be done on it. The information needs to be stored somewhere—either in memory, on disk, or on the network.

OS X and iOS provide tools for storing information on disk and on the network. One of the more recent additions to the APIs available to developers is iCloud, a network-based storage system that is designed to allow users to keep the same information on all their devices, without having to do any work to enable this.

Additionally, Cocoa is designed to make the connection between the model, the view, and the controller as flexible as possible, while at the same time reducing the amount of code that you need to write. To this end, Cocoa uses features called key-value coding, which allows you to refer to properties of objects by name rather than by hardcoding method calls, and key-value observing, which allows you to have an object be notified when another object changes the value of one of its properties.

In this chapter, you will learn how key-value coding and key-value observing work, why they’re useful, and how to use them in your code. You will also learn how to work with the filesystem ...

Get Learning Cocoa with Objective-C, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.