Created
August 18, 2014 07:24
-
-
Save jsooriah/cdcda3136c572cae7d89 to your computer and use it in GitHub Desktop.
This file contains 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)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