How to Add a Property List to Your iOS App
Given the versatility of property lists, you’re sure to turn to them for your iOS app time and time again. Follow these steps to incorporate a plist into your Xcode project:
In the Project navigator, add a RoadTrip Resources group to Supporting Files. Right-click it, and then choose New File from the menu that appears to get the New File dialog.
Or select the RoadTrip Resources group and choose File➪New➪New File from the main menu (or press ⌘+N).
In the left column of the New File dialog, select Resource under the iOS heading, select the Property List template in the top-right pane, and then click Next.
A Save sheet appears.
Enter Destinations in the Save As field.
Click Create (and make sure that the Target field has the RoadTrip check box selected).
A property list will be created with a single element called Root; it is a dictionary, but you can change it to be an array if you want.
Right-click in the Root row to show the context-sensitive menu; then choose Add Row.
You can also choose Editor➪Add Item to add a row.
A new row appears.
Enter DestinationData in the Key field, replacing New Item (which should be highlighted).
Click in the up and down arrows in the Type field and then choose Array from the pop-up menu that appears.
Click the disclosure triangle in front of the DestinationData key so it is pointing down and click the + (plus) button.
DestinationData is an array of dictionaries that will hold all your destination-specific information, with Item 0 being the first one.
You can see the + (plus) button in the new row.
Make Item 0 a dictionary by selecting Dictionary in the Type pop-up menu (in the same way you select Array in Step 7).
Your new entry is made into a dictionary.
Click the disclosure triangle in front of the Item 0 key so that it points down, and click the + (plus) button as you did in Step 7 to add a new entry to the dictionary.
You see a new entry under the dictionary.
These disclosure triangles work the same way as those in the Finder and the Xcode editor. The Property List editor interprets what you want to add based on the triangle. So if the items are revealed (that is, the triangle is pointing down), the editor assumes that you want to add a sub item or child.
If the sub items are not revealed (that is, the triangle is pointing sideways), the editor assumes that you want to add an item at that level (sibling). In this case, with the arrow pointing down, you add a new entry — a sub item — to the dictionary. If the triangle were pointing sideways, you would be entering a new entry under the root.
Only arrays and dictionaries have children.
In the Key field of your newest entry, enter DestinationName, leave the Type as String, and then double-click (or tab to) the Value field and enter New York City.
Click the + button in the row you just entered, and you get a new entry (a sibling of the previous row). In the Key field, enter DestinationImage, leave the Type as String, and then double-click (or tab to) the Value field and enter NYCImage.
Click the + button in the row you just entered, and you get a new entry (a sibling of the previous row). In the Key field, enter DestinationLocation and select Dictionary in the Type pop-up menu.
Click the disclosure triangle in front of the DestinationLocation key so it’s facing down, and click the + button.
You see a new entry under the dictionary.
In the Key field, enter Title, and enter New York City in the Value field.
Add these three keys with their corresponding type and value:
Key Type Value Subtitle String A great city Latitude Number 40.712756 Longitude Number −74.006047
Click the disclosure triangle to hide the DestinationLocation dictionary entries, and add a new array named Events as a sibling of the DestinationLocation.
When the disclosure triangle is closed, you add a sibling entry.
Continue filling out the plist.
Key Type Value DestinationName String New York City DestinationImage String NYCImage DestinationLocation Dictionary Title String New York City Subtitle String A great city Latitude Number 40.712756 Longitude Number -74.006047 Events Array Item 0 String http://jessefeiler.com/NYC01.html Item 1 String http://jessefeiler.com/NYC02.html POIs Array Item 0 Dictionary Title String The Statue of Liberty Subtitle String Pro-democracy and anti-monarchy symbol of freedom Latitude Number 40.689244 Longitude Number -74.044514 Weather String http://forecast.weather.gov/MapClick.php?zoneid=NYZ072
After you finish entering these items, close Item 0 under DestinationData and go through Steps 8 through 18 again to add the San Francisco entry using the keys and values below. If you want to save some typing, you can copy and paste Item 0 and then expand the new Item 1 and simply replace the values.
|Subtitle||String||A great city|
|Title||String||Golden Gate Bridge|
|Subtitle||String||An internationally recognized symbol of San Francisco|
Make sure that you spell the entries exactly as specified or else you won’t be able to access them. Be especially careful of trailing spaces.
You may wonder why you’re using this specific data (title and subtitle, for example). You’ll understand that when you explore maps.