User Defaults

When you need to save a little bit of data in your app, the NSUserDefaults object is a very simple and easy way to do so. NSUserDefaults is a front-end to a key-value file (often referred to as Plist files because of the .plist extension) that is stored in the app’s Preferences directory. There’s only one file, but in this file you can store as many values as you want. When storing values in the file, you have to supply a key string to identify the value when retrieving it later. You can store many data types in NSUserDefaults, including all scalar types as well as NSData, NSString, NSNumber, NSDate, NSDictionary, and NSArray. Other data types can be archived and stored as an NSData object.

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.