You’re previewing Ry’s Cocoa Tutorial

Persistent Data

So far, we’ve only been working with an in-memory representation of our model layer. As soon as we close the app, any changes to the data are lost forever. Obviously, this is not an ideal situation for most OS X applications. In this chapter, we’ll learn how to save our model layer so that it persists from one application launch to the next.

Cocoa includes three different persistent storage options. They each provide different levels of functionality, but they share the common goal of saving and loading data. From simplest to most complex, they are:

Each option is designed to store a different type of data. The preferences system is for recording simple values like whether the user wants a dark background or a light background in their UI (hence the name, “preferences”). Property lists are for saving native data types like NSArray to a file. Finally, object archives let you to save custom objects like ProductData to disk.

Saving the model layer to persistent storage

This chapter will also discuss Cocoa’s built-in file system capabilities, including how to manipulate file paths, access the standard OS X directories, and let the user select files with the open and save panels. By the end of this chapter, you should be comfortable saving and loading any kind of data your app needs.

Sorry, this is the end of the preview. To read the rest of this chapter, you’ll need to purchase Ry’s Cocoa Tutorial.

Mailing List

Sign up for my low-volume mailing list to find out when new content is released. Next up is a comprehensive Swift tutorial planned for late January.

You’ll only receive emails when new tutorials are released, and your contact information will never be shared with third parties. Click here to unsubscribe.