O'Reilly logo

Learning Cocoa with Objective-C, 2nd Edition by James Duncan Davidson, Apple Computer Inc

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 15. Defaults and Preferences

Most applications need to store and retrieve preferences that allow for user customization of an application’s behavior and keep track of configuration settings. Mac OS X provides, as part of its Core Foundation framework, a preferences system that provides a simple and standard way to maintain these preferences. Cocoa calls these preferences defaults.

If you go to the ~/Library/Preferences folder, you will see the user-preferences database used by the applications you run on your system. In fact, many of the applications we have created in this book have written preferences to this database. Take a look, and you’ll see that you probably have Dot View.plist, Menu.plist, and RTF Edit.plist files. These contain preferences used by some of the various Cocoa base classes used in the sample applications we’ve built throughout the book.

In this chapter we’ll show you how to take advantage of the user-preferences system from your applications using Cocoa.

How Preferences Work

The preference system in Mac OS X allows you to store values associated with a key—the name of a property—that can later be used to look up the preference value when you need it. These key-value pairs are scoped using a combination of username and application ID. All of the preferences for a user are stored in his ~/Library /Preferences folder.

There are multiple domains—or different scopes of coverage—in which a preference can exist. When you request a preference, the following ...

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