Storing Data with NSUserDefaults

NSUserDefaults is a quick and easy way to store small amounts of data for you app. It basically acts as a key-value persistent store and is straighforward to use.

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:@"value" forKey:@"key"];
[standardUserDefaults synchronize];

You can also store integer, double and float values. Retrieving values is straightforward as well.

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *value = [standardUserDefaults stringForKey:@"key"];

It can be a very useful tool in the right situation. Happy coding.

Tags: iOS, Objective-C