Ionut Branzei Ionut Branzei - 1 year ago 81
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

Answer Source

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"]];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download