Objective-cで2つのNSSetをマージするにはどうすればよいですか?
グーグルで解決策が見つかりません。
これは、NSSetのメソッドの中から簡単に見つけることができます。
- (NSSet *) setByAddingObjectsFromSet:(NSSet*) other;
セットの1つがNSMutableSet
thenの場合、次の例のように、和集合演算を使用できます。
// 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];
2セットをマージする場合に使用できます。
NSSet *mergedSet = [set setByAddingObjectsFromSet:set];
配列をセットにマージする場合は、次を使用できます
NSSet *mergedSet = [set setByAddingObjectsFromArray:array];