Dev:Preferences


 * This article is about reading and writing preferences. For the Preferences user interface framework, see Preferences.framework.

Tweaks typically have preferences that can be set by the user from the Settings app. The Preferences framework uses the CFPreferences family of functions to read and write preferences. Before OS X 10.8 and iOS 8, these functions would directly read and write a plist with the name of the application identifier in. (Note that when an app is sandboxed in a container, the home directory is the path to the container, not the user's home directory.) Nowadays, preferences are managed by a daemon called cfprefsd.

The Foundation class NSUserDefaults provides a subset of features over the CFPreferences functions. It appears to be intended more as a simple-to-use class that handles calling CFPreferences functions for you, as opposed to being feature-by-feature compatible with CFPreferences.

CFPreferences functions can take and return CFStringRefs and CFPropertyListRefs. As such, you can toll-free bridge these from or to their matching Foundation classes.

cfprefsd
cfprefsd is the daemon that handles reading and writing preference values. It also caches values in memory so that they can be returned faster. Its goal is to avoid disk reads/writes as much as is possible. This has caused some confusion among tweak developers who have for the most part simply been reading their preference plist directly from the disk, which isn't written to until cfprefsd decides to flush its in-memory cache, or it's sent a SIGTERM. It was introduced to OS X with 10.8, and to iOS with 8.0.

Due to cfprefsd not working as desired in processes that live in an app container and having no documentation other than a vague man page, various developers have created different solutions to read and write preference values. These are outlined at PreferenceBundles &sect; Loading Preferences.

The signal SIGUSR1 can be sent to cfprefsd to make it write a file to. It provides data about each preference domain read or written to using CFPreferences APIs since the daemon started, in the following form:

Examples
''To do: read this carefully and move all information regarding preferences to a more appropriate place. Bring the following contents:''


 * Dev:PreferenceBundles
 * Dev:Updating extensions for iOS 8

Tweak part
As opposed to using NSDictionaries and, the following implementation uses NSUserDefaults, which works properly for unsandboxed processes, so read the previous links to handle preferences on sandboxed processes until an implementation is added here.

Preference plist
Choose any of the following styles, see preferences specifier plist for all available specifier types and how to use them.

Reduced style
Provides a switch on the root section of the preferences (like Airplane Mode). Recommended for configuration-less tweaks.

Saved in your tweak's folder as

Extended Style
Provides a pane where other cells can appear (like Wi-Fi). Recommended for configuration-friendly tweaks.

Saved in your tweak's folder as

Inside PreferenceBundles
Provides a static list of cells. Recommended for Preference Bundles of tweaks.

Saved in your tweak's Preference Bundle subproject folder as

Flipswitches
After using the Flipswitch NIC template, modify accordingly