O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with NSUserDefaults Object

The NSUserDefaults object is used to store data values for an app in a key-value list on the disk. Working with NSUserDefaults is very simple. You start by getting a reference to the standard NSUserDefaults object with this line of code:

NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];

To store a value in the settings object, you use code like this:

[settings setObject:@"City" forKey:@"sortField"];

This saves the value “City” with the key “sortField”. Every value must have a unique key. In addition to the setObject:forKey: method, there are also methods that can be used to store scalar values such as BOOL and int. Here’s an example: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required