Ionut Branzei Ionut Branzei - 10 months ago 43
iOS Question

Access a dictionary key from another dictionary in plist

enter image description hereplist of Dealers and Cars

I want to have access to the dealer name from the plist.

- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Cars" ofType:@"plist"];

NSArray *array = [NSArray arrayWithContentsOfFile:filePath];
NSMutableArray *dealers = [[NSMutableArray alloc] init];
for (NSDictionary *object in array) {
Dealer *dealer = [[Dealer alloc] initWithDictionary:object];
[dealers addObject:dealer];
self.dealers = dealers;

From this, i access just the first dictionary from plist


The first NSDictinonary in you plist has Item 0 key that store Dealer NSDictinonary. Change your string code

 Dealer *dealer = [[Dealer alloc] initWithDictionary:object];

to this

 Dealer *dealer = [[Dealer alloc] initWithDictionary:object[@"Dealer"]];