Get started with the Property List Editor
The Property List Editor enables you to create “plist” resources (files). In this document, you learn how to get started with the editor.
Sometimes, it is convenient to provide “starter data” for your iOS app. If you wish, you can provide the data as a property list, known as a plist.
Xcode includes a plist editor. Mac OS X also includes a standalone app, called Property List Editor. See the following topics from the Property List Programming Guide:
Creating a plist
We’ll use Xcode as the plist editor. In your left-side groups and files navigator, right-click the Resources group. Choose Add > New File.
In the New File dialog, on the left-side navigator, select “Mac OS X” > “Resource”.
In the template viewer, choose “Property List”. The new plist will appear in the editor:
Notice that the current item is highlighted, with a light-blue background.
Notice also the icon on the right side of the highlighted item.
|This icon indicates that the item is a container – a Dictionary, or an Array|
|This icon indicates that the item is a leaf node – a String, Number, Boolean, Date, or Data|
The icon, when clicked, enables you to add a new item:
- The “add item in container” icon will add a new item inside the container; for a Dictionary, it adds a key-value pair; for an Array, it adds an array element
- The “add item” icon will add a new leaf node item, at the same level as the current item
The “Root” item
In a new plist, there is one “root” item. Its default type is Dictionary, although you can choose Array as an alternative.
Note: Choose either Dictionary, or Array, as your root item type.
Let’s build an array, with three elements. Each array element will be a dictionary, with two key-value pairs.
First, change the type to Array. Then, click the container icon, to add a new item inside the array container.
Change the type of that new item to Dictionary. Make sure that your plist looks like the following before we continue:
Notice the disclosure triangle to the left of “Item 0”. When collapsed, the item/row’s add icon is the “add item” icon. Click to open the disclosure triangle, and notice that the item/row’s add icon changes to the “add item in container” icon. Your plist should now look like this:
Now, click the highlighted item’s “add item in container” icon, to add a new item inside the dictionary container.
We will create a key-value pair for a String, and one more for a Number. Change the type as appropriate. Enter the values. For a Dictionary, you must also enter appropriate names for the keys. When you finish, it should look similar to the following:
Now that you have created the first array element, you can use copy-paste to easily create the other array elements. Here’s how:
- Click to close the array element’s disclosure triangle (“Item 0” above).
- If necessary, click to select/highlight the “Item 0” item/row.
- Right-click the highlighted row, and choose “Copy”.
- Right-click either the highlighted row, or the “Root” item/row, and choose “Paste”.
- Repeat as necessary.
- Click to open each new element’s disclosure triangle, and edit the values.
Your plist should now look similar to the following:
Save your work. You can now use this plist in your app, by reading it into an NSArray instance.