Example of using NSSet

The set is initialized with objects, NSString constants in this case. The "nil" at the end is required.

 planetNames= [NSMutableSet setWithObjects:@"earth.png", @"mars.jpg",
             @"jupiter.jpg", @"mercury.jpg", @"antique.png", nil];

To remove an object from a set, you first get a reference (pointer) to it, and you immediately retain it. Then you remove the object, which will automatically release it (hence the need to retain it first). Return the pointer.

NSString * getAName()
{
 NSString * returnString = [[planetNames anyObject] retain];
 [planetNames removeObject:returnString]; 
 return returnString;
 }

To return the object, add it to the set, which will retain it. You then release it.

void returnAName(NSString *pName)
{
  [planetNames addObject:pName];
  [pName release];
}