O'Reilly logo

iOS App Development Portable Genius by Richard Wentk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

bullet_2c.tif NSArray. Each object in the collection is numbered sequentially with an index, which starts at 0.

bullet_2c.tif NSDictionary. Each object is associated with a unique key, which can be a text string or some other object.

bullet_2c.tif 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required