NSUserDefaults

In this exercise, we will 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 set and remove objects in it using a key. It is also automatically read from disk when the application first accesses it and written to disk when modified.

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.