views:

51

answers:

1

Basically I have an NSMutableArray set up like so, with instances of another class as the array elements.

[[NSMutableArray alloc] initWithObjects: [[Shape alloc] init], [[Shape alloc] init], nil];

Each of the shape classes has an instance variable that holds what kind of shape it is. I want to be able to make this array so that it assigns a value to the instance variable, something like this, where ShapeVariable is the instance variable in the Shape class, and Square/Circle is the value I want it to have.

[[NSMutableArray alloc] initWithObjects: [[Shape alloc] initwith ShapeVariable Square], [[Shape alloc] initwith ShapeVariable Circle], nil];

Also, I would like to know how to assign two instance variables at the same time to the same element.

+1  A: 

The developer tools installation includes an example called Sketch. It basically does exactly what you want and is very carefully reviewed by the team that develops the Cocoa framework with every release of the OS to make sure that it follows the "most modern" rules and APIs.

Regardless of whether or not your final goal is to target the iPhone, starting with that example will likely prove to be extremely useful.

You'll find it in /Developer/Examples/Sketch/.

bbum