PSPreferences

Plain C on CoreFoundation types. Available from anywhere, including a constructor that runs before much else is set up.

Include
#import "PSPreferences.h"

Reading

Signatures
CFPropertyListRef PSPreferencesCopyAppValue(CFStringRef key, CFStringRef domain);
Boolean           PSPreferencesGetAppBooleanValue(CFStringRef key, CFStringRef domain, Boolean *exists);
CFIndex           PSPreferencesGetAppIntegerValue(CFStringRef key, CFStringRef domain, Boolean *exists);
CFArrayRef        PSPreferencesCopyKeyList(CFStringRef domain);

The Copy functions follow the CoreFoundation create rule: you own the result and must CFRelease it. They return NULL when the key is absent.

exists is how the typed getters distinguish a stored false or 0 from nothing stored at all. Pass NULL if you do not need to tell them apart.

Writing

Signatures
void    PSPreferencesSetAppValue(CFStringRef key, CFPropertyListRef value, CFStringRef domain);
Boolean PSPreferencesAppSynchronize(CFStringRef domain);

Passing NULL as the value removes the key. Call PSPreferencesAppSynchronize when you need the write on disk before continuing.

Example

C
Boolean exists = false;
Boolean enabled = PSPreferencesGetAppBooleanValue(CFSTR("enabled"),
                                                  CFSTR("com.example.mytweak"),
                                                  &exists);
if (!exists) enabled = true;   // your default

CFNumberRef n = PSPreferencesCopyAppValue(CFSTR("intensity"),
                                          CFSTR("com.example.mytweak"));
if (n) { /* use it */ CFRelease(n); }

See also

PSUserDefaults for the same store with typed accessors and registered defaults, which removes the exists dance above.