Set Objects

A set is a collection of unique objects, and it can be mutable or immutable. Operations include searching, adding, and removing members (mutable sets); comparing two sets; and finding the intersection and union of two sets.

In this section, we take a quick look at three set classes: NSSet, NSMutableSet, and NSIndexSet. We also mention the class NSCountedSet in passing so that you will know when you might need or want to use that set.

Program 15.19 shows some basic operations on sets. Suppose, for instance, that you want to display the contents of your sets several times during execution of the program. You therefore decide to create a new method called print. You add the print method to the NSSet class by creating a new category ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.