November 15, 2010

How to save User preferences in iPhone app

Saving user preferences in iPhone app is fairly easy. It work as key/value pairs in NSUserDefaults object.


To save whether user prefers sounds on or off in your application you can do it as the following code block.

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"soundsOn"];

And to retrieve the sounds preferences value;


BOOL soundsOn = [[NSUserDefaults standardUserDefaults] boolForKey:@"soundsOn"];

No comments: