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
.
You should read this document to understand the programmatic interface for interacting with the Mac OS X user defaults system using Cocoa.
This programming topic contains the following articles:
“Defaults Domains” describes the various defaults domain groupings.
“Using NSUserDefaults” describes how to create and save user defaults.
User Defaults and Bindings describes the role of NSUserDefaultsController
and how it works with NSUserDefaults
.
Storing NSColor in User Defaults describes how to store colors in an application’s user defaults.
© 2001, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)