Skip to content

Instantly share code, notes, and snippets.

@luqmaan
Created April 19, 2013 13:53
Show Gist options
  • Save luqmaan/5420508 to your computer and use it in GitHub Desktop.
Save luqmaan/5420508 to your computer and use it in GitHub Desktop.
Is there a faster/easier way to loop through the NSArray of NSDictionaries and find a NSDictionary with a specific key/value?
"routes": [{
"id": "Hillsborough Area Regional Transit_6",
"textColor": "FFFFFF",
"color": "09346D",
"description": "",
"longName": "56th Street",
"shortName": "6",
"type": 3,
"agencyId": "Hillsborough Area Regional Transit",
"url": "http://www.gohart.org/routes/hart/06.html"
}, {
"id": "Hillsborough Area Regional Transit_5",
"textColor": "FFFFFF",
"color": "09346D",
"description": "",
"longName": "40th Street",
"shortName": "5",
"type": 3,
"agencyId": "Hillsborough Area Regional Transit",
"url": "http://www.gohart.org/routes/hart/05.html"
}, {
"id": "Hillsborough Area Regional Transit_2",
"textColor": "FFFFFF",
"color": "09346D",
"description": "",
"longName": "Nebraska Avenue",
"shortName": "2",
"type": 3,
"agencyId": "Hillsborough Area Regional Transit",
"url": "http://www.gohart.org/routes/hart/02.html"
},
for (NSDictionary *route in [[[tripsDict objectForKey:@"data"]
objectForKey:@"references"]
objectForKey:@"routes"])
{
if ([[route objectForKey:@"id"] isEqualToString:routeId]) {
[routeName appendString:[route objectForKey:@"shortName"]];
[routeName appendString:[route objectForKey:@"longName"]];
break;
}
}
@aklowther
Copy link

for (NSDictionary *route in tripsDict[@"data"][@"references"][@"routes"]
{

}

should work and you get the benefit of using literals...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment