Managing Data Collections
It’s often useful to collect objects together and work with them as a group. For example, if you have a collection of views in a UI design, performing some operation on all of them can be useful.
iOS includes three data collection objects that store other objects. You’ll see these objects used throughout iOS. When iOS needs to pass a collection of data to a method in your app, it often arrives wrapped inside one of these objects. You’ll find you regularly use these objects to manage data collections of your own.
There are three object types, and they organize the data in different ways, as follows:
NSArray. Each object in the collection is numbered sequentially with an index, which starts at 0.
NSDictionary. Each object is associated with a unique key, which can be a text string or some other object.
NSSet. Objects aren’t ordered, but you can retrieve objects from the set, and you can test whether an object is included in the set. Testing is quite speedy: It’s faster than for the other collection objects.
Figure 7.2 shows the Class Reference for NSArray. If you’re familiar with arrays in C, you can see that NSArray is far more powerful. You can search for ...