NoviceDeveloper
NoviceDeveloper

Reputation: 225

How to Pass Specific value from one array to another

I have create a array containg person firstname,lastmane and number. Now i want to create another array containing only firstname. This might be a simple question but i am not able to do it.Any help will be appreciated. Here is my code.

        - (void)viewDidLoad {
 [super viewDidLoad];
 productArray=[[NSMutableArray alloc]init];

 PersonDetail *personObj = [[PersonDetail alloc] init];
 personObj.firstName = @"Adeem";
  personObj.lastName = @"Basraa";
 personObj.phoneNumber = @"123456789";

 [productArray addObject:personObj];
 [personObj release];

 PersonDetail *personObj = [[PersonDetail alloc] init];
 personObj.firstName = @"Ijaz";
 personObj.lastName = @"Ahmed";
 personObj.phoneNumber = @"987654321";

   [productArray addObject:personObj];
 [personObj release];

PersonDetail *personObj = [[PersonDetail alloc] init];
personObj.firstName = @"Waqas";
personObj.lastName = @"Noor";
personObj.phoneNumber = @"45656789";
[productArray addObject:personObj];
[personObj release];

Upvotes: 0

Views: 95

Answers (1)

DarkDust
DarkDust

Reputation: 92384

You mean like this?

NSMutableArray *firstNames = [NSMutableArray array];
for (PersonDetail *person in productArray) {
    [firstNames addObject:person.firstName;
}

Upvotes: 1

Related Questions