Skip to content

Instantly share code, notes, and snippets.

@DougFischer
Created November 26, 2013 02:07
Show Gist options
  • Select an option

  • Save DougFischer/7652434 to your computer and use it in GitHub Desktop.

Select an option

Save DougFischer/7652434 to your computer and use it in GitHub Desktop.
- (void)subtrateUncomparablePoints {
//Dictionary to store the values before and after subtration
NSMutableDictionary *dictionaryWithValuesByKeys = _plotPoints;
NSMutableDictionary *filteredDictionary = [[NSMutableDictionary alloc] init];
//Store the dates that must be displayed
NSCountedSet *countedSet = [[NSCountedSet alloc] init];
//Iterate all points and count how many times date is found
for (NSArray *values in [dictionaryWithValuesByKeys allValues]) {
for (PKPlotPoint *point in values) {
[countedSet addObject:point.date];
}
}
//Keep only dates found for the same keys count
[countedSet filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ([countedSet countForObject:evaluatedObject] == dictionaryWithValuesByKeys.count);
}]];
//Iterate each original values array filtering by enough counted dates
for (NSString *key in [dictionaryWithValuesByKeys allKeys]) {
NSArray *values = [dictionaryWithValuesByKeys objectForKey:key];
values = [values filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.date IN (%@)", countedSet]];
[filteredDictionary setObject:values forKey:key];
}
//Log
NSLog(@"Filtered: %@", filteredDictionary);
//Store on property
_plotPoints = filteredDictionary;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment