Skip to Main Content
iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch
book

iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

by Maher Ali
March 2009
Beginner to intermediate content levelBeginner to intermediate
396 pages
8h 44m
English
Wiley
Content preview from iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch

Chapter 2. Collections

As a Cocoa developer, you are provided with many classes that can help you group several of your objects together in specific ways. In this chapter, we discuss the main collection classes available to you.

The chapter is organized as follows. In Section 2.1, we address the topic of arrays. You will learn about immutable and mutable arrays, the different approaches used for copying arrays, and several sorting techniques. Section 2.2 covers the topic of sets. Sets are collections that do not impose ordering on the objects they contain. You will learn about immutable and mutable sets as well as several interesting operations on sets. In Section 2.3, we discuss dictionaries. Dictionaries allow you to store objects and retrieve them using keys. As you have seen in Section 1.7, dictionaries are widely used in Cocoa frameworks and understanding them is essential. Finally, we provide a summary in Section 2.4.

Arrays

You use NSArray and NSMutableArray if you would like to store/access your objects in an ordered way. NSArray is the immutable version of the array, allowing you to store your objects only once (during initialization). NSMutableArray is a subclass of NSArray that allows you to add/remove objects even after initialization of the collection.

To help illustrate the main concepts behind these two classes, let us use the simple class Person shown in Listing 2.1.

Example 2.1. The class Person used in the arrays examples.

#import <Foundation/Foundation.h>

@interface ...
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.
Start your free trial

You might also like

Microsoft® Office Access 2007 on Demand

Microsoft® Office Access 2007 on Demand

Steve Johnson - Perspection, Inc.
FileMaker Pro 14: The Missing Manual

FileMaker Pro 14: The Missing Manual

Stuart Gripman, Susan Prosser
Microsoft® Office Access™ 2007 Step by Step

Microsoft® Office Access™ 2007 Step by Step

Steve Lambert Joan Lambert and M. Dow Lambert III

Publisher Resources

ISBN: 9780470742822Purchase book