You are looking for an algorithm to find the power of multiple intersections.
Depending on your presentation of the set, you can choose different ways to execute it. The most indicative of this would be the use of bits in an integer, but if the number of possible interests exceeds 64, it can be difficult to implement.
An easy way to implement it would be an NSMutableSet , for example:
// Prepare the individual lists NSArray *chris = @[@"bowling", @"gaming", @"skating", @"running"]; NSArray *brad = @[@"bowling", @"jumping", @"walking", @"sitting"]; // Obtain the intersection NSMutableSet *common = [NSMutableSet setWitArray:chris]; [common intersectSet:[NSSet setWithArray:brad]]; NSLog(@"Common interest count: %i", common.count);
source share