Created
April 19, 2013 13:53
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for (NSDictionary *route in tripsDict[@"data"][@"references"][@"routes"]
{
}
should work and you get the benefit of using literals...