December 2013
Intermediate to advanced
464 pages
14h 46m
English
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: ...
Read now
Unlock full access