Lee Armstrong
Lee Armstrong

Reputation: 11450

Filling Array with Custom Class - retrieving values

I have the following code

NSMutableArray *leeTemp = [[NSMutableArray alloc] init];
Player* playerLee = [[Player alloc] init];
playerLee.name = [array objectAtIndex:1];
[leeTemp addObject:playerLee];
[playerLee release];

And this generates an array of Players (I think)! When I do the following it shows the addresses of the Players.

NSLog(@"%@",leeTemp);

What I am struggling with is retreiving say array[0].name, this is a string value. I'm sure this is very simple but am struggling to visualise this.

Upvotes: 0

Views: 231

Answers (1)

Louis Gerbarg
Louis Gerbarg

Reputation: 43452

You want to do:

NSLog(@"%@", [[leeTemp objectAtIndex:0] name]);

Or if you want to loop through an array you can use for..in iteration:

for (Player *player in leeTemp) {
  NSLog(@"%@", [player name]);
}

Upvotes: 1

Related Questions