Skip to content

Instantly share code, notes, and snippets.

@jsooriah
Created August 18, 2014 07:24
Show Gist options
  • Save jsooriah/cdcda3136c572cae7d89 to your computer and use it in GitHub Desktop.
Save jsooriah/cdcda3136c572cae7d89 to your computer and use it in GitHub Desktop.
- (void)decomposeFlightsPerHour {
self.decomposedFlights = [NSMutableDictionary dictionary];
NSMutableArray *temp = [NSMutableArray array];
NSString *currentHourPrefix = [[[self.flightList objectAtIndex:0] objectForKey:@"HP"] substringToIndex:2];
NSString *dateHourPrefix = [[[self.flightList objectAtIndex:0] objectForKey:@"DATEVOL"] substringToIndex:10];
NSString *newPrefix = [NSString stringWithFormat:@"%@_%@", dateHourPrefix, currentHourPrefix];
for (NSDictionary *flightInfo in self.flightList) {
NSString *flightInfoHourPrefix = [[flightInfo objectForKey:@"HP"] substringToIndex:2];
NSString *flightInfoDatePrefix = [[flightInfo objectForKey:@"DATEVOL"] substringToIndex:10];
NSString *flightInfonewPrefix = [NSString stringWithFormat:@"%@_%@", flightInfoDatePrefix, flightInfoHourPrefix];
if ([flightInfonewPrefix isEqualToString:newPrefix]) {
[temp addObject:flightInfo];
} else {
NSArray *temp_buffer = [temp copy];
[self.decomposedFlights setObject:temp_buffer forKey:newPrefix];
currentHourPrefix = [[flightInfo objectForKey:@"HP"] substringToIndex:2];
dateHourPrefix = [[flightInfo objectForKey:@"DATEVOL"] substringToIndex:10];
newPrefix = [NSString stringWithFormat:@"%@_%@", dateHourPrefix, currentHourPrefix];
[temp removeAllObjects];
}
}
self.sortedHourKeys = [[self.decomposedFlights allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableDictionary *tempDict = [NSMutableDictionary dictionary];
NSString *key;
for (key in self.decomposedFlights) {
if ((((NSArray *)[self.decomposedFlights objectForKey:key]).count != 0)) {
[tempDict setObject:[self.decomposedFlights objectForKey:key] forKey:key];
}
}
[self.decomposedFlights removeAllObjects];
self.decomposedFlights = tempDict;
self.decomposedFlightsCleaned = tempDict;
[self.departuresTableView reloadData];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment