Check if NSArray contains some int

Viewed 11764

I have a NSMutableArray of NSNumbers. Basically I just want to check if any of the NSNumbers in the array = some value.

I could iterate through the array, checking one by one, by this is by no means optimal.

I also tried and failed using containsObject, because this only works if the id's are the same.

I read something about NSPredicate, this seems like a good solution, but I am not sure on how to use it with an NSArray.

Any answer is appreciated.

Thanks

6 Answers

You can simply check like this:

if ([myArray indexOfObject:@(myNumber)] == NSNotFound) {
    NSLog(@"myArray' contauns 'myNumber");
}

Keep Coding.......... :)

Related