Sep 8, 2008

(iPhone) How to use Preference

Writing a simple data to preference:

CFStringRef textColorKey = CFSTR("defaultTextColor");
CFStringRef colorBLUE = CFSTR("BLUE");
// Set up the preference.
CFPreferencesSetAppValue(textColorKey, colorBLUE,
kCFPreferencesCurrentApplication);
// Write out the preference data.
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);

Reading a simple data from preference:

CFStringRef textColorKey = CFSTR("defaultTextColor");
CFStringRef textColor;
// Read the preference.
textColor = (CFStringRef)CFPreferencesCopyAppValue(textColorKey,
kCFPreferencesCurrentApplication);
// When finished with value, you must release it
// CFRelease(textColor);

To replace the exist key's value, just overwrite the values of key.

No comments: