title: Check duplicate objects in NSMutableArray?
body: <p>I am adding objects (NSNumbers in this case) to an NSMutableArray and I wanted to check what the best way is to check for duplicates in the array before adding. (i.e.)</p>
  
  <pre><code>Number to add
  if (NSMutableArray does not contain Number) {
      add Number
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Many thanks, I had a good luck at NSArray this morning but totally missed "containsObject". That would have done just fine, but having looked at NSMutableSet thats far more what I was looking for. One final question if I may:</p>
  
  <pre><code>while([mySet count] &lt; 5) {
      NSNumber *numberToAdd = [NSNumber numberWithInt:random() %10];
      [mySet addObject:numberToAdd];
  }
  </code></pre>
  
  <p>I don't think it actually matters, but is it better to check if the set "containsObject" or just throw away the duplicate and carry on.</p>
  
  <pre><code>while([mySet count] &lt; 5) {
      NSNumber *numberToAdd = [NSNumber numberWithInt:random() %10];
      if(!mySet containsObject:numberToAdd) [mySet addObject:numberToAdd];
  }
  </code></pre>
  
  <p>Again much appreciated, thats really cool and will save me a heap of time.</p>
  
  <p>gary</p>