This is a simple method to compare two arrays and get all the common objects from these arrays.
Take two arrays(say firstArray & secondArray)
NSMutableSet* arraySet1 = [NSMutableSet setWithArray:firstArray]; //create NSMutableSet for firstArray
NSMutableSet* arraySet2 = [NSMutableSet setWithArray:secondArray]; //create NSMutableSet for secondArray
[arraySet1 intersectSet:arraySet2]; //this will assign all common(intersecting) values of two sets to arrayset1
NSArray* arrayResult = [arraySet1 allObjects]; // assign all the object of arraySet1 to arrayResult
For Example:
firstArray=(
abc,
pqr
)
secondArray=(
abc,
pqr
)
arrayResult is=(
pqr
)
0 Comment(s)