title: Objective C - NSArray and For loop structure
body: <p>Work got in the way of learning Objective C but i'm back at it now and this has been driving me crazy.</p>
  
  <p>This is my code:</p>
  
  <pre><code>i=0;
      for (i=0;[photoList count]; i++) {
          NSLog(@"%i",i);
          NSLog(@"%@",[photoList objectAtIndex:i]);
          NSString *fileName = [photoList objectAtIndex:i];
          sendImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
          UIImageWriteToSavedPhotosAlbum(sendImage,self,@selector(savedPhotoImage:didFinishSavingWithError:contextInfo:),NULL);}
  </code></pre>
  
  <p>photoList is just an NSArray like so, except with 24 objects:</p>
  
  <pre><code>NSArray* photoList = [NSArray arrayWithObjects:@"Photo 1.jpg",
      @"Photo 2.jpg",
      @"Photo 3.jpg",
      @"Photo 4.jpg",nil];
  </code></pre>
  
  <p>It works... It copies the photos to the camera roll... and then crashes with</p>
  
  <p>2010-07-24 19:34:36.116 iCardz2go Poindexter[29662:207] <strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[NSArray objectAtIndex:]: index 24 beyond bounds [0 .. 23]'</p>
  
  <p>I've tried various configurations such as</p>
  
  <pre><code>for (i=0;1&lt;23; i++)
  </code></pre>
  
  <p>only to get 
  2010-07-24 19:51:01.017 iCardz2go Poindexter[29908:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'</p>
  
  <p>So it's reading the nil and passing it.</p>
  
  <p>I know its going to be something real simple that I've forgotten. Why doesn't it jump out the loop at Photo 23 (the count)?</p>
  
  <p>Your help is greatly appreciated!
  P</p>