Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You would like to store an array of objects but you don’t want any one object to appear more than once in the array.
Sets are very similar to arrays. The big difference is that sets
allow objects to be added only once. The second time you try to add
the same object, it will be rejected by the set. We use NSSet for immutable and NSMutableSet for mutable sets. Let’s have a
look at an example of an immutable set:
NSString *hisName = @"Robert";
NSString *hisLastName = @"Kiyosaki";
NSString *herName = @"Kim";
NSString *herLastName = @"Kiyosaki";
NSSet *setOfNames = [[NSSet alloc] initWithObjects:
hisName,
hisLastName,
herName,
herLastName, nil];
NSLog(@"Set = %@", setOfNames);