title: How to split an NSArray into two equal pieces?
body: <p>I have an NSArray, and I want to split it into two equal pieces (if odd "count" then add to the latter new array) - I want to split it "down the middle" so to speak.  </p>
  
  <p>The following code does exactly what I want, but is there a better way?:</p>
  
  <pre><code>// NOTE: `NSArray testableArray` is an NSArray of objects from a class defined elsewhere;
  NSMutableArray *leftArray = [[NSMutableArray alloc] init];  
  NSMutableArray *rightArray = [[NSMutableArray alloc] init];
  
  for (int i=0; i &lt; [testableArray count]; i=i+1) {
  if (i &lt; [testableArray count]/2) {
          [leftArray addObject:[testableArray objectAtIndex:i]];
      }
      else {
          [rightArray addObject:[testableArray objectAtIndex:i]];
      }
  }
  </code></pre>
  
  <p>Once leftArray and rightArray are made, I will not change them, so they do not need to be "mutable".  I think there may be a way to accomplish the above code with the ObjectsAtIndexes method or some fast enumeration method?, but I cannot get the following code to work (or other variations):</p>
  
  <pre><code>NSArray *leftArray = [[NSArray alloc] initWithObjects:[testableArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(????, ????)]]];
  NSArray *rightArray = [[NSArray alloc] initWithObjects:[testableArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(????, ????)]]];
  </code></pre>
  
  <p>Does anyone know if I am going in the right direction with this or point me in the correct direction?</p>
  
  <p>Thanks!</p>