开发者

How can I access class variable inside a NSMutableArray object?

I have "Man" class which also has 2 variable : "description" and "name". At a point, I created Man class and initialize with its own variables (description and name) and pass it to NSMutableArray "collector". How can I access description now ? I tried but ı could not get the prop开发者_开发知识库erty


If I understand you correctly, the Man object will now be an object in the collector array. If so, you would access it like:

Man *man = [collector objectAtIndex:42];
NSString *description = [man description];

42 is just an arbitrary index, and objectAtIndex: is just one method to access an object in an array (any number of other ways could be used). In the second statement, I've also assumed that you have declared description and name as properties of the Man class, so that they can be accessed from other classes via accessors/mutators (a.k.a getters/setters).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜