문제

Just a quick question regarding sets in Obj-c. Given two sets:

NSMutableSet* a = [NSMutableSet setWithObjects: 1, 2, 3, nil];
NSMutableSet* b = [NSMutableSet setWithObjects: 3, 4, 5, nil];

is there a quick and easy way to determine if any element in set A is also in set B?

Something like ...

if ([a contains:[b allObjects]])
   // do something
도움이 되었습니까?

해결책

This is what -intersectsSet: is for.

if ([a intersectsSet:b])
    // do something

다른 팁

The word you're looking for is "intersect" :)

if ([a intersectsSet:b]) {
    ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top