Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sunsunai

macrumors newbie
Original poster
Oct 11, 2015
2
0
Hi, I have a plist file with Root's type is Array, 20 items with type is Dictionary, each item have 3 keys (Name, Position, Number) and thier type is String. I want to get a key Position where's value is "Mid". I just can get all of thier Values not which value i want.

This is my code till now.

Code:
  //get URL from plist file.

    NSString* path = [[NSBundlemainBundle]pathForResource: @"playersList"ofType: @"plist"];

    //Save plist file to an NSMutableArray

    self.playerOfList = [[NSMutableArrayalloc]initWithContentsOfFile: path];

Code:
NSDictionary* playerShow = [[self.playerOfList objectAtIndex:indexPath.row]objectForKey: @"Position"];

    NSLog(@"%@", playerShow);

Please help, thanks.
 
Last edited by a moderator:
The best thing would be to create a new array called midArray that is an array of dictionary's, I would do something like
Code:
NSMutableArray *midArray =[[NSMutableArray alloc] init];

For (int x = 0, x <= self.playerlist.count, x++){
     If ([[self.playerlist objectForIndex:x]safeItemForKey:"position"] isEqualToString:"mid"]
     {
          [midArray addObject:[self.playerlist objectForIndex:x]];
     };
};

Hope this makes sense, sorry wrote it free hand in my phone
 
Last edited:
The best thing would be to create a new array called midArray that is an array of dictionary's, I would do something like
Code:
NSMutableArray *midArray =[[NSMutableArray alloc] init];

For (int x = 0, x <= self.playerlist.count, x++){
     If ([[self.playerlist objectForIndex:x]safeItemForKey:"position"] isEqualToString:"mid"]
     {
          [midArray addObject:[self.playerlist objectForIndex:x]];
     };
};

Hope this makes sense, sorry wrote it free hand in my phone

It really make sense, now i can print all of my player with position Mid. Very thank you. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.