//创建方法
NSMutableSet*set1 = [NSMutableSetset];//空集合,有意义
NSMutableSet*set2 = [NSMutableSetsetWithCapacity:100];//预估值
NSMutableSet*set3 = [NSMutableSetsetWithObjects:@"one",@"two",@"three",nil];//标准方法,最常用的方法
NSLog(@"%@", set3);
//添加方法
[set3addObject:@"four"];//添加一个元素
NSLog(@"%@", set3);
[set3addObject:@"four"];//添加时,会自动调用hash、isEqual方法过滤掉重复的元素
NSLog(@"%@", set3);
NSArray*added =@[@"five",@"six"];
[set3addObjectsFromArray:added];//批量添加
NSLog(@"%@", set3);
//删除方法
[set3removeObject:@"three"];//删除一个
NSLog(@"%@", set3);
[set3removeAllObjects];//清空集合
NSLog(@"%lu", set3.count);
//交集
NSArray*added1 =@[@"one",@"two",@"three"];
[set2removeAllObjects];
[set2addObjectsFromArray:added1];
NSArray*added2 =@[@"one",@"three",@"four"];
[set3removeAllObjects];
[set3addObjectsFromArray:added2];
[set2intersectSet:set3];//计算结果别放回到set2中
NSLog(@"%@", set2);
//并集
[set2unionSet:set3];
NSLog(@"%@", set2);
//从一个集合中删除另一个集合的元素
[set2removeAllObjects];
[set2addObjectsFromArray:added1];
[set3removeAllObjects];
[set3addObjectsFromArray:added2];
[set2minusSet:set3];
NSLog(@"%@", set2);