Retrieve name of Object in Array


#1

This one has me stumped, looking for some ideas.

Like many others, I created 3 separate named objects containing my stocks (myStocks, momStocks, dadStocks) and put them in a NSMutableArray named familyStocks. Now, it’s easy for me to loop through familyStocks and pull all of the information for the NSLog as the challenge asked for.

HOWEVER, how can/do I access the name of the individual objects (not the object class name) i.e. “myStocks”, “momStocks”, etc…

Thinking I need to be using an NSDictionary (sorry, jumping ahead here) rather than an NSMutableArray

Ideas?

Regards,

Mark H


#2

I had this same question too but then I realize that in order to do this, you need to add another instance variable (string) and of course create setters/getters for that new variable.

That’s the best way to do it.


#3

Hi Mark,

the “Names” you’ve given are simply variables, pointing at those objects. Information about them is not stored in the instances. If you want to add some titles, then you’ll need an extra field (like NSString *_shareTitleAbbr) with its own getter / setter methods. Then you’ll be able to ask for it while working with the instance.

Best Regards,
JB