Using NSUserDefaults

What we need to do now is store a value to specify the map type that the user last selected so that the chosen type will automatically be displayed when the user launches the application again. This value will be stored in an instance of NSUserDefaults.

Every application has an instance of NSUserDefaults that it can access by sending the class message standardUserDefaults to the NSUserDefaults class. This instance of NSUserDefaults is like an NSMutableDictionary; you can access objects in it using a key. It is also automatically read from disk when the application first accesses it and written to disk when it is modified.

The keys of an NSUserDefaults are always of type NSString. A key identifies a preference. An object ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.