Arrays and Dictionaries in Action
The sooner you reach comfort levels with the NSArray and NSDictionary classes (and their mutable
subclasses) the sooner you’ll be able to apply these data structures to
many critical iOS app uses. Although you will see several specific
applications in Chapter 9,
let me whet your appetite.
When you inspected TheElements sample application, you saw that all data for the atomic elements displayed throughout the app arrived in the form of a .plist file. Open that project in Xcode and click on the Elements.plist file (inside the Resources group). Figure 8-9 shows the beginning of the file in the editor window.

Figure 8-9. Start of Elements.plist file content
The property list is formatted at its root as an array of 118
members. This is an NSArray type, which means that you can create
an NSArray object in code by loading
this file directly into it (via the arrayWithContentsOfFile: class method). That’s
all you need to do to create the app’s giant array from data delivered
with the app. Other apps might download frequently updated data stored as
a .plist file on a server—yet another
way to get data into a live app (but via the asynchronous NSURLConnection class, rather than NSArray’s synchronous arrayWithContentsOfURL: class method).
Now, notice that each of the 118 members of the root array is a dictionary. Expand the first item (Item 0) to see what the dictionary ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access