Preferences Utilities


Several functions return a preference value as a Core Foundation property list object. You can use the function CFGet​Type​ID(_:​) to determine the value’s type. For more information about property lists, see Property List Programming Topics for Core Foundation.


Core Foundation provides a simple, standard way to manage user (and application) preferences. Core Foundation stores preferences as key-value pairs that are assigned a scope using a combination of user name, application ID, and host (computer) names. This makes it possible to save and retrieve preferences that apply to different classes of users. Core Foundation preferences is useful to all applications that support user preferences. Note that modification of some preferences domains (those not belonging to the “Current User”) requires root privileges (or Admin privileges prior to OS X v10.6)—see Authorization Services Programming Guide for information on how to gain suitable privileges.

Unlike some other Core Foundation types, CFPreferences is not toll-free bridged to its corresponding Cocoa Foundation framework class (NSUser​Defaults). CFPreferences is thread-safe.


Getting Preference Values

func CFPreferences​Copy​App​Value(CFString, CFString)

Obtains a preference value for the specified key and application.

func CFPreferences​Copy​Key​List(CFString, CFString, CFString)

Constructs and returns the list of all keys set in the specified domain.

func CFPreferences​Copy​Multiple(CFArray?, CFString, CFString, CFString)

Returns a dictionary containing preference values for multiple keys.

func CFPreferences​Get​App​Boolean​Value(CFString, CFString, Unsafe​Mutable​Pointer<Darwin​Boolean>?)

Convenience function that directly obtains a boolean preference value for the specified key.

func CFPreferences​Get​App​Integer​Value(CFString, CFString, Unsafe​Mutable​Pointer<Darwin​Boolean>?)

Convenience function that directly obtains an integer preference value for the specified key.

Setting Preference Values

func CFPreferences​Set​Multiple(CFDictionary?, CFArray?, CFString, CFString, CFString)

Convenience function that allows you to set and remove multiple preference values.

func CFPreferences​Set​Value(CFString, CFProperty​List?, CFString, CFString, CFString)

Adds, modifies, or removes a preference value for the specified domain.

Synchronizing Preferences

func CFPreferences​App​Synchronize(CFString)

Writes to permanent storage all pending changes to the preference data for the application, and reads the latest preference data from permanent storage.

func CFPreferences​Synchronize(CFString, CFString, CFString)

For the specified domain, writes all pending changes to preference data to permanent storage, and reads latest preference data from permanent storage.

Adding and Removing Suite Preferences

func CFPreferences​Add​Suite​Preferences​To​App(CFString, CFString)

Adds suite preferences to an application’s preference search chain.

func CFPreferences​Remove​Suite​Preferences​From​App(CFString, CFString)

Removes suite preferences from an application’s search chain.

Miscellaneous Functions


Application, Host, and User Keys

Keys used to specify the common preference domains.