Created
November 26, 2013 02:07
-
-
Save DougFischer/7652434 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| - (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