Chapter 21. Preferences and Defaults

If you’ve used an operating environment other than Mac OS X (such as Windows or Unix), you’ve probably had to worry about environment variables and configuration files. Such nuisances are pointedly missing from most Mac OS X applications, because Mac OS X uses a database to store all such configuration and user-preferences information. This database is called the defaults database .

The Mac OS X defaults database stores the preferences set in the Preferences dialogs of all applications. As a Cocoa programmer, you can use the defaults database system to store whatever information you want.

The Mac OS X defaults database is similar to the registry in Microsoft Windows, but with one critical difference — Mac OS X applications use this database only for storing preferences, not for storing critical information that is necessary for the proper operation of an application. Unlike Windows, where registry keys must be created when an application is installed, Mac OS X applications create their defaults entries when they run — and they automatically recreate the settings if they are accidentally or intentionally removed. Furthermore, the settings in the defaults system never contain full application pathnames — applications find where they are installed by examining their MainBundles (the directory from which the application is run). Thus, you can move an application and it will still work properly.

In this chapter, we’ll modify the GraphPaper program ...

Get Building Cocoa Applications: A Step by Step Guide 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.