可变集合 NSMutableSet

//创建指定元素个数的一个集合对象

        NSMutableSet *set = [NSMutableSet setWithCapacity:10];

        

//添加一个对象到集合

        [set addObject:@"adsf"];

        NSLog(@"%@", set);

        

//从集合中删除一个对象

        [set removeObject:@"adsf"];

        NSLog(@"%@", set);

        

//把数组对象添加到集合对象中去

        NSArray *array = [[NSArray alloc]initWithObjects:@"125"@"qew"@"sd526fs"nil];

        [set addObjectsFromArray:array];

        NSLog(@"%@", set);

        

//得交两个集合的交集

        NSMutableSet *set1 = [NSMutableSet setWithObjects:@"123"@"456"@"789"nil];

        NSMutableSet *set2 = [NSMutableSet setWithObjects:@"123"@"456"@"987"nil];

        //[set1 intersectSet:set2];  //得到的交集把set1的值替代,set2值不变

        NSLog(@"%@", set1);

//从一个集合中减去另一个交集,就是求前一个集合和后一个集合的不同元素值

        NSMutableSet *set3 = [[NSMutableSet allocinitWithObjects:set1, nil];

       [set3 addObject:set2];

//一个集合减去另一个集合

       [set3 minusSet:[NSMutableSet setWithObjects:set2, nil]];

NSLog(@"%@", set3);

原文地址:https://www.cnblogs.com/Azazqing/p/3696586.html