如何在objective-c中合并2个NSSets?

ane*_*yzm 14 cocoa nsset

如何在objective-c中合并2个NSSets?

我在谷歌找不到解决方案.

ham*_*ene 32

在NSSet的方法中很容易发现:

- (NSSet *) setByAddingObjectsFromSet:(NSSet*) other;
Run Code Online (Sandbox Code Playgroud)


Tom*_*sel 5

如果其中一个集合是a,NSMutableSet则可以使用union操作,如下例所示:

// Create / Get the sets
NSMutableSet *firstSet = [NSMutableSet setWithArray:@[@"1", @"2"]];
NSSet *secondSet = [NSSet setWithArray:@[@"3",@"4"]];

// Add missing values from the second set to the first set
[firstSet unionSet:secondSet];
Run Code Online (Sandbox Code Playgroud)