title: how does UILocalizedIndexedCollation work? (sample code from documentation)
body: <p>how does <code>UILocalizedIndexedCollation</code> work?</p>
  
  <p>i was reading the <code>simpleIndexedTableView</code> <a href="http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Listings/3_SimpleIndexedTableView_Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40007318-3_SimpleIndexedTableView_Classes_RootViewController_m-DontLinkElementID_18" rel="nofollow">sample code</a> from the documentation, the <code>RootViewController</code> is initialized, we send it some data ( <code>rootViewController.timeZonesArray = timeZones;</code> ) but at this point, <code>collation</code> is already used in the view controller : </p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      // The number of sections is the same as the number of titles in the collation.
      return [[collation sectionTitles] count];
  }
  </code></pre>
  
  <p>basically this is where the magic seems to happen, so what does  <code>[collation sectionTitles]</code> contain? something must be automatic, but i don't see how the whole thing worked?</p>
  
  <pre><code>- (void)configureSections {
  
      // Get the current collation and keep a reference to it.
      self.collation = [UILocalizedIndexedCollation currentCollation];
  
      NSInteger index, sectionTitlesCount = [[collation sectionTitles] count];
  
      NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
  
      // Set up the sections array: elements are mutable arrays that will contain the time zones for that section.
      for (index = 0; index &lt; sectionTitlesCount; index++) {
          NSMutableArray *array = [[NSMutableArray alloc] init];
          [newSectionsArray addObject:array];
          [array release];
      }
  
      // Segregate the time zones into the appropriate arrays.
      for (TimeZoneWrapper *timeZone in timeZonesArray) {
  
          // Ask the collation which section number the time zone belongs in, based on its locale name.
          NSInteger sectionNumber = [collation sectionForObject:timeZone collationStringSelector:@selector(localeName)];
  
          // Get the array for the section.
          NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:sectionNumber];
  
          //  Add the time zone to the section.
          [sectionTimeZones addObject:timeZone];
      }
  
      // Now that all the data's in place, each section array needs to be sorted.
      for (index = 0; index &lt; sectionTitlesCount; index++) {
  
          NSMutableArray *timeZonesArrayForSection = [newSectionsArray objectAtIndex:index];
  
          // If the table view or its contents were editable, you would make a mutable copy here.
          NSArray *sortedTimeZonesArrayForSection = [collation sortedArrayFromArray:timeZonesArrayForSection collationStringSelector:@selector(localeName)];
  
          // Replace the existing array with the sorted array.
          [newSectionsArray replaceObjectAtIndex:index withObject:sortedTimeZonesArrayForSection];
      }
  
      self.sectionsArray = newSectionsArray;
      [newSectionsArray release]; 
  }
  </code></pre>
  
  <p>Thanks for your help</p>