Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Multiple Views: A table with a view > Arrays (and more) have built-in suppor...

Arrays (and more) have built-in support for plists

Changing the array initialization code to use the plist is remarkably easy. Most Cocoa collection types like NSArray and NSDictionary have built-in support for serializing to and from a plist. As long as you’re using built-in types (like other collections, NSStrings, etc.), you can just ask an array to initialize itself from a plist.

The only piece missing is telling the array which plist to use. To do that, we’ll use the project’s resource bundle, which acts as a handle to application-specific information and files. Add the bolded code below to your RootViewController.m file.

image with no caption

Test Drive

After you’ve finished up these two things, go ahead and build and run. It should look the same, with just the three drinks.

Ready Bake plist

image with no caption

Once this list works, head over to http://www.headfirstlabs.com/books/hfiphonedev/ and download the DrinkArray.plist file. It has the complete list of the drinks from the Head First Lounge. Drop this in on top of your test plist, rebuild DrinkMixer, and try it out!

Test Drive

image with no caption

The whole list is in there now!

image with no caption

Creating your detail view will complete the app.

The entire list of drinks is great, but Sam still needs to know what goes in those views and how to make them. That information is going to go in the detail view that we sketched up earlier.

Brain Barbell

How are we going to get from the list to the detail view? And how are we going to display the details?

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint