开发者

Question about an NSMutableArray of a certain class

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 th开发者_如何学Ce same element.


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/.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜