Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

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:

  1. 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).

  2. 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.

  3. Enter Destinations in the Save As field.

  4. 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.

  5. Right-click in the Root row to show the context-sensitive menu; then choose Add Row.

    image0.jpg

    You can also choose Editor➪Add Item to add a row.

    A new row appears.

    image1.jpg
  6. Enter DestinationData in the Key field, replacing New Item (which should be highlighted).

  7. Click in the up and down arrows in the Type field and then choose Array from the pop-up menu that appears.

    image2.jpg
  8. 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.

    image3.jpg
  9. Make Item 0 a dictionary by selecting Dictionary in the Type pop-up menu (in the same way you select Array in Step 7).

    image4.jpg

    Your new entry is made into a dictionary.

  10. 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.

    image5.jpg

    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.

  11. 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.

  12. 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.

    image6.jpg
  13. 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.

  14. 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.

    image7.jpg
  15. In the Key field, enter Title, and enter New York City in the Value field.

    image8.jpg
  16. 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
  17. Click the disclosure triangle to hide the DestinationLocation dictionary entries, and add a new array named Events as a sibling of the DestinationLocation.

    image9.jpg

    When the disclosure triangle is closed, you add a sibling entry.

  18. 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.

Key Type Value
DestinationName String San Francisco
DestinationImage String SFImage
DestinationLocation Dictionary
Title String San Francisco
Subtitle String A great city
Latitude Number 37.7793
Longitude Number −122.4192
Events Array
Item 0 String http://jessefeiler.com/SF01.html
Item 1 String http://jessefeiler.com/SF02.html
POIs Array
Item 0 Dictionary
Title String Golden Gate Bridge
Subtitle String An internationally recognized symbol of San Francisco
Latitude Number 37.819722
Longitude Number −122.478611
Weather String http://forecast.weather.gov/MapClick.php?site=mtr&textField1=37.76&textField2=-122.43&smap=1

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.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.