Next Page > Hide TOC

Introduction to User Defaults

Contents:

Who Should Read This Document
Organization of This Document


This programming topic describes the programmatic interface for interacting with the Mac OS X user preferences system—also known as the user defaults system—using Cocoa. Preference settings let you offer ways for users to customize the appearance or behavior of your software. The user defaults system lets you access and manage user preferences. You can use the defaults system to provide reasonable initial values for application settings, as well as save and retrieve the user's own preference selections across sessions.

The NSUserDefaults class only supports the storage of objects that can be serialized to property lists. This limitation would seem to exclude many kinds of objects, such as NSColor and NSFont objects, from the user default system. But if objects conform to the NSCoding protocol they can be archived to NSData objects, which are property list–compatible objects. For information on how to do this, see “Storing NSColor in User Defaults“; although this article focuses on NSColor objects, the procedure can be applied to any object that can be archived.

NSUserDefaults does not currently support per-host preferences. To do this, you must use Preferences Utilities Reference. However, NSUserDefaults correctly reads per-host preferences, so you can safely mix CFPreferences code with NSUserDefaults.

Who Should Read This Document

You should read this document to understand the programmatic interface for interacting with the Mac OS X user defaults system using Cocoa.

Organization of This Document

This programming topic contains the following articles:



Next Page > Hide TOC


© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.