Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if NSMutableArray contains values from another array

I have an 3 NSMutableArray objects that contain CMTime objects. How can I iterate through all three of them in an efficient manner and find out if there are duplicate values in all three? For example, I'm iterating through one of time and reading the value and storing it in x. Now, I want to see if x occurs (at any position) within the other two arrays. I tried looking for a contains method, but couldn't find one. I did come across filterUsingPredicate, but I'm not sure if this is the best way of doing it nor how to actually use predicates.

like image 251
XSL Avatar asked Mar 19 '26 19:03

XSL


1 Answers

I tried looking for a contains method, but couldn't find one.

Use indexOfObject:

like this:

if ([array indexOfObject:object] != NSNotFound) {
    // object found
}
else {
    // object not found
}
like image 116
Matthias Bauch Avatar answered Mar 21 '26 09:03

Matthias Bauch