I have two json files which are linked by key country_id (one country – many cities), data from a json file I write in NSDictionary s.
question : if i selected one of the countries from first NSDictionary (dictionary of countries data) how to show all the data that is bind to selected country_id in other dictionary(dictionary of cities data)?
What i tried?
I tried to do next:check all key values of second NSDictionary(dictionary of cities data) is they equal to selected county_id
//dict3 - dictionary of cities data
for (int i = 0; i<=[[dict3 valueForKey:@"country_id"] count];i++)
{
if ([[[dict3 valueForKey:@"country_id"] objectAtIndex:i] isEqualToString:appDelegate.idSelectedCountry])
{
NSLog(@"object %@",[nameCities objectAtIndex:i]); //array of cities name
}}
But because my JSON files are quite big this is takes too long to compute.
You should use Core data for this kind of thing and have there a relation on City and Country entity. it will be faster and more correct. Look at this tutorial:
http://www.raywenderlich.com/934/core-data-on-ios-5-tutorial-getting-started
Update:
If you want for some reasons really use NSDictionary as you do now, you can at least employ blocks. It is little bit faster than loops: