RetainAll method function is in java what is alternative method in objective-C
sample code in java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MainClass {
public static void main(String args[]) {
String orig[] = { "1st", "2nd", "3rd", "4th", "5th", "1st", "2nd", "3rd",
"4th", "5th" };
String act[] = { "2nd", "3rd", "6th" };
List origList = new ArrayList(Arrays.asList(orig));
List actList = Arrays.asList(act);
System.out.println(origList.retainAll(actList));
System.out.println(origList);
}
}
The out put which gives 2nd 3rd 2nd 3rd
There isn’t a simple method for this in NSArray, but you can achieve the same effect with a predicate:
As Tim Dean points out, this is normally an operation on sets rather than arrays, and NSSet does have methods for doing it. If your application actually could use a set here, that’s probably the best approach instead of shoehorning set behavior into an array. But if you need to keep the original ordering, you’ll have to do it with a predicate.