Retrieving a Preference

The simplest way to locate and retrieve a preference value is to use the CFPreferencesCopyAppValue function. This call searches through the various preference domains in order until it finds the key you have specified. It returns as soon as it finds the specified key, allowing values in more specific domains (lower numbered) to override those in more general (higher numbered) domains. If a preference has been set in a less-specific domain--"any application", for example --its value is retrieved with this call if a more specific version cannot be found. Listing 1-2 shows how to retrieve the text color preference saved in Listing 1-1.

Listing 1-2 Retrieving a preference value
CFStringRef textColorKey = CFSTR("defaultTextColor"); CFStringRef textColor; // Read the preference. textColor = CFPreferencesCopyAppValue(textColorKey, kCFPreferencesCurrentApplication);


© 2000 Apple Computer, Inc. (Last Updated 14 July 2000)