title: Getting a random object from an array, then remove it from array. iphone
body: <p>I am having a problem with arrays, I want an object to be picked randomly from the array,
  and then remove it and remove other objects that are specified in the "if" statement.</p>
  
  <p>What I did..</p>
  
  <p>in the .h </p>
  
  <pre><code>NSMutableArray *squares;
  int s;
  NSString *randomN;
  </code></pre>
  
  <p>Next, in the .m</p>
  
  <p>Create a new array:</p>
  
  <pre><code>-(void) array{
      squares = [[NSMutableArray alloc] arrayWithObjects: @"a", @"b", @"c", nil];
  }
  </code></pre>
  
  <p>and then choose a random object, if properties of the "if" met, remove the object from the array, do the while loop again.</p>
  
  <pre><code>-(void) start{
  
      s=5;
  
      while (s &gt; 0){
       //I even tried it without the next line..
       randomN = nil;
  
       //Also tried the next line without ' % [squares count'
       randomN = [squares objectAtIndex:arc4random() % [squares count]];
  
       if (randomN == @"a"){
           [squares removeObject: @"a"];
           [squares removeObject: @"b"];
          s = s - 1;
          }
  
       if (randomN == @"b"){
           [squares removeObject: @"b"];
           [squares removeObject: @"c"];
          s = s - 1;
          }
  
       if (randomN == @"c"){
           [squares removeObject: @"c"];
          s = s - 1;
          }
  
       else {
       s=0;
       }
  }
  }
  </code></pre>
  
  <p>When I run the app, the app stops and quits as soon as the loop starts.</p>
  
  <p>Can you please help me?</p>