Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for item in array without looping

I have an array and I want to check if one string is in the array, without looping. Just using "if's" I know if some string exists or not in the array.

Is there any possibility?


1 Answers

Use -[NSArray containsObject:].

(You don't have to write the loop yourself, but of course NSArray almost certainly has to use a loop internally.)

if ([array containsObject:string])
    NSLog(@"Yes, the array contains my string.")
like image 111
Kurt Revis Avatar answered Jul 06 '26 05:07

Kurt Revis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!