Saving and retrieving data from NSUserDefaults

September 26th, 2011

NSUserDefaults is a great way to save small amounts of data that you want to persistent across application "sessions" (especially where a database would be overkill).

A photo of a pile of files

Saving data:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:KEY_TO_IDENTIFY_INFORMATION];

In the above, we save the value: YES with the key:

KEY_TO_IDENTIFY_INFORMATION

Retrieving data:

[[NSUserDefaults standardUserDefaults] boolForKey:KEY_TO_IDENTIFY_INFORMATION]

What do you think? Let me know by getting in touch on Twitter - @wibosco