1.                 NSMutableArray *tableSections = [[NSMutableArray alloc] init];
  2.         NSMutableArray *sectionData = [[NSMutableArray alloc] init];
  3.         NSMutableArray *yourCustomDataObject;
  4.        
  5.         int sectionIndex;
  6.        
  7.         // Pseudo-code to create data structure
  8.         for(id episode in episodes) {
  9.             sectionIndex = [[episode objectForKey:@"Season"] intValue];
  10.            
  11.             yourCustomDataObject = [[NSMutableArray alloc] initWithObjects:episode, nil];
  12.            
  13.             // Do index check first to insure no out of bounds
  14.             if(sectionIndex <= [tableSections count]) { // tableSections will always count 0
  15.                 sectionData = [tableSections objectAtIndex:sectionIndex];
  16.             }
  17.            
  18.             // Create the new section array if there isn't one for the current section
  19.             if(!sectionData) {
  20.                 sectionData = [NSMutableArray new];
  21.                 [tableSections insertObject:sectionData atIndex:sectionIndex];
  22.             }
  23.            
  24.             [sectionData addObject:yourCustomDataObject];
  25.         }
  26.        
  27.         NSLog(@"%d %d", [tableSections count], [sectionData count]);