preferences snippets

How to store user settings with NSUserDefaults

Tagged nsuserdefaults, preferences, settings, objective-c  Languages objectivec

Storing preferences

NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
[preferences setObject:@"SOME_DATA" forKey:@"KEY"];

Retrieving preferences

[preferences stringForKey:@"KEY"];
[preferences integerForKey:@"KEY"];
[preferences booleanForKey:@"KEY"];

Listing preferences with the defaults command

To list all preferences for a specific app, use this command:

$ defaults read com.aktagon.XXXApp

References

http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/UserDefaults.html