Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS filter an array with an array
    primarykey
    data
    text
    <p>I have an array of strings that I want to use as the filter for another array of dictionaries that is created from a plist. For example, if I had a plist of dictionaries that looked like so:</p> <pre><code>Key: Value: car1 audi car2 bmw car3 bmw car4 audi car5 jaguar </code></pre> <p>and my array of strings was "audi, jaguar". How would I code it so that I can create a new array that would return "car1, car4, car5"? Hope this makes sense. Or better yet, how can I walk down this dictionary and filter it based on a value and then create a new array of dictionaries to use.</p> <p>Code:</p> <pre><code>-(void)plotStationAnnotations { desiredDepartments = [[NSMutableArray alloc] init]; BOOL tvfrSwitchStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"tvfrSwitchStatus"]; BOOL hfdSwitchStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"hfdSwitchStatus"]; if (tvfrSwitchStatus) { NSString *tvfr = @"TVF&amp;R"; [desiredDepartments addObject:tvfr]; } if (hfdSwitchStatus) { NSString *hfd = @"HFD"; [desiredDepartments addObject:hfd]; } NSLog(@"Array 1 = %@", desiredDepartments); NSString *path = [[NSBundle mainBundle] pathForResource:@"stationAnnotations" ofType:@"plist"]; NSMutableArray *anns = [[NSMutableArray alloc] initWithContentsOfFile:path]; NSMutableArray *newDictionaryArray = [NSMutableArray array]; for (NSDictionary *dictionary in anns) { for (NSString *string in desiredDepartments) { if ([dictionary allKeysForObject:string]) { [newDictionaryArray addObject:dictionary]; break; } } } NSLog(@"Array = %@", keyMutableArray); for (int i = 0; i &lt; [keyMutableArray count]; i++) { float realLatitude = [[[keyMutableArray objectAtIndex:i] objectForKey:@"latitude"] floatValue]; float realLongitude = [[[keyMutableArray objectAtIndex:i] objectForKey:@"longitude"] floatValue]; StationAnnotations *myAnnotation = [[StationAnnotations alloc] init]; CLLocationCoordinate2D theCoordinate; theCoordinate.latitude = realLatitude; theCoordinate.longitude = realLongitude; myAnnotation.coordinate = theCoordinate; myAnnotation.title = [[keyMutableArray objectAtIndex:i] objectForKey:@"station"]; myAnnotation.subtitle = [[keyMutableArray objectAtIndex:i] objectForKey:@"department"]; [mapView addAnnotation:myAnnotation]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload