title: Looping through an array to remove a touched object (iPhone/Cocos2d)
body: <p>I am using cocos2d to build a game. I have an array of CCSprites and I want to be able to touch them and delete the one that was touched.</p>
  
  <p>Right now I have this...</p>
  
  <pre><code>-(void) spawn {
     mySprite = [CCSprite spriteWithFile:@"image.png"];
     mySprite.position = ccp(positionX,positionY);
     [myArray addObject:mySprite];
     [self addChild:mySprite];
  }
  - (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     UITouch* touch = [touches anyObject];
     CGPoint location = [touch locationInView: [touch view]]; 
  
      NSUInteger i, count = [myArray count];
      for (i = 0; i &lt; count; i++) {
      mySprite = (CCSprite *)[myArray objectAtIndex:i];
      if (CGRectContainsPoint([mySprite boundingBox], location)) {
  
         [self removeChild:mySprite cleanup:YES]; 
  
      }
  }
  </code></pre>
  
  <p>I have never done this before. Does anyone have a solution?</p>
  
  <p>Thanks,
  Michael</p>