Check if NSArray contains some int

    NSPredicate *valuePredicate=[NSPredicate predicateWithFormat:@"self.intValue == %d",[myValueNumber intValue]];

    if ([[numbersArray filteredArrayUsingPredicate:valuePredicate] count]!=0) {   
        // FOUND
    }

    else  {
       //NOT FOUND
    }

Iterating through the array is the best approach here. This is exactly what the containsObject method is doing under the covers. You could sort the array, but that wouldn't give you very much in terms of efficiency.

If you want to be able to look up values quicker than O(n), NSArray/NSMutableArray is probably not the right data structure for you.


a little late, but since the array is already ordered (sorted) you should use CFArrayBSearchValues() which does binary search.

example with numbers:

NSArray *array; // or NSMutableArray
NSNumber *value; // search value
CFArrayBSearchValues((__bridge CFArrayRef)array, CFRangeMake(0, array.count),                   
        (CFNumberRef)value, (CFComparatorFunction)CFNumberCompare, NULL);

Inspired by bernstein I looked up some more info about the and i found CFArrayContainsValue

BOOL CFArrayContainsValue(CFArrayRef theArray, CFRange range, const void *value);

Example:

NSArray *numbers;
NSNumber *value;
BOOL found = CFArrayContainsValue ( (__bridge CFArrayRef)numbers, 
                                    CFRangeMake(0, numbers.count), 
                                    (CFNumberRef)value );

Works like a charm and is really fast!