title: Get sectionIndex titles based on contact name
body: <p>In my app I have a db with 50k+ contacts. To display them on list view, I need to calculate the index section titles to display them on the right side. </p>
  
  <p>However my logic is taking time around 3-6 seconds to prepare the datasource. </p>
  
  <pre><code>-(NSArray *)getSectionTitleBasedOn:(NSString*)sortBy{
  
      for (RealmContact *contact in contactSource){
  
          if (contact.firstName.length&gt;0) {
              if ([sortBy isEqualToString:@"FirstName"]) {
  
                  NSString *firName= [contact.firstName stringByReplacingOccurrencesOfString:@" " withString:@""];
                  NSString *regex = @"^[A-Za-z]+";
                  NSPredicate *test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
                  BOOL result = [test evaluateWithObject:firName];
  
                  if (contact.firstName.length&gt;0 &amp;&amp; result)
                  {
                      [nameDic setObject:@"firstletter" forKey:[[contact.firstName substringToIndex:1]uppercaseString]];
                  }else{
                       [nameDic setObject:@"firstletter" forKey:@"#"];
                  }
              }
              if ([sortBy isEqualToString:@"LastName"]) {
                  //same
              }
              if ([sortBy isEqualToString:@"Company"]) {
                  //same
              }
  
          }
      }
      NSLog(@"dic %@",nameDic);
      return [[nameDic allKeys]sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
  }
  </code></pre>
  
  <p>I'm wondering if there is anything I could do to improve this. </p>
  
  <pre><code> NSString *firName= [contact.firstName stringByReplacingOccurrencesOfString:@" " withString:@""];
   NSString *regex = @"^[A-Za-z]+";
    NSPredicate *test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL result = [test evaluateWithObject:firName];
  </code></pre>
  
  <p>I'm doing this to check if string contain special chars or invalid chars.</p>
  
  <p>After I get the array, I sort it and return the array. The output would be:</p>
  
  <pre><code>dic {
      "#" = firstletter;
      A = firstletter;
      B = firstletter;
      C = firstletter;
      D = firstletter;
      E = firstletter;
      F = firstletter;
      G = firstletter;
      H = firstletter;
      I = firstletter;
      J = firstletter;
      K = firstletter;
      L = firstletter;
      M = firstletter;
      N = firstletter;
      O = firstletter;
      P = firstletter;
      Q = firstletter;
      R = firstletter;
      S = firstletter;
      T = firstletter;
      U = firstletter;
      V = firstletter;
      W = firstletter;
      X = firstletter;
      Y = firstletter;
      Z = firstletter;
  }
  </code></pre>