Lesson 22

Property Lists

A property list is an XML key-value store that allows applications to store small amounts of data locally. Property lists are best suited to storing small amounts of data (less than a few hundred kilobytes). It is quite common for applications to use property lists to store application configuration information, such as server addresses and URLs.

Creating Property Lists

A property list can be created using the property list editor, or programmatically. The GUI property list editor that is integrated with XCode displays a property list file as a hierarchy of nodes and elements, all contained under a root node (see Figure 22.1). The root node can be either an array or a dictionary.

Screenshot of GUI property list editor with the property list file.

Figure 22.1

To create a property list, add a new file to the project and select Property List from the iOS Resource section in the file options dialog box (see Figure 22.2).

Screenshot of Resource section in file options dialog box, with Property List highlighted.

Figure 22.2

This will add an empty property list file to your project, with a single dictionary element called Root (see Figure 22.3).

Screenshot of plisteditor with names.plist highlighted, and single dictionary element in the center section.

Figure 22.3

To add a new entry to the property list, select the parent node and select Editor Add Item (see Figure 22.4).

Figure 22.4

The default data type ...

Get Swift iOS 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.