Chapter 22

Property Lists

iOS devices have the capability to store data locally. The data is organized into a name/value relationship and uses the standard XML format. Apple recommends that the decision as to when to use property lists to persist data should be limited to small amounts, preferably less than a few hundred kilobytes. For larger amounts, Apple offers Core Data as an alternative solution.

Property lists are used quite frequently in standard Apple applications. For example, the application’s user settings are stored in a property list. The Settings app requires a specific format, but the structure is a property list.

Property List Types

To convert the XML element values in a property list into an Objective C object, Apple has defined the following relationships between the Objective C object and the property list’s XML element value, as shown in Table 22-1.

Table 22-1: Property List Types

Data Type XML Tag iOS Class
array < array> NSArray
dictionary < dictionary> NSDictionary
string < string> NSString
data < data> NSData
date < date> NSDate
integer < integer> NSNumber (intValue)
floating point <real> NSNumber (floatValue)
Boolean <true/> or <false/> NSNumber (boolValue) YES or NO

Creating Property Lists

You can create property lists in two ways:

  • Programmatically
  • Using the property list editor

Programmatically

You can create a property list programmatically directly in Objective-C if all of the objects derive from the NSDictionary, NSArray, ...

Get iPhone and iPad App 24-Hour Trainer 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.