集合 不可变

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
//可变集合
        NSMutableSet *set1=[NSMutableSet set];
        NSMutableSet *set2=[NSMutableSet setWithObjects:@"1",@"2", nil];
        NSMutableSet *set3=[NSMutableSet setWithObjects:@"a",@"2", nil];
        
    //用集合2减去集合3中的元素,最后集合2中的元素只剩1个,值为1
        NSLog(@"%@",set2);
        NSLog(@"%@",set3);
       // [set2 minusSet:set3];
       // NSLog(@"%@",set2);
        //NSLog(@"%@",set3);
    //集合2与集合3交集,最后集合2中的元素只有1个,值为2
        //[set2 intersectSet:set3];
//        NSLog(@"%@",set2);
//        NSLog(@"%@",set3);
    //集合2与集合3并集,最后集合2中的元素有3个,1,2,a
        [set2 unionSet:set3];
        NSLog(@"%@",set2);
        NSLog(@"%@",set3);
    //移除集合中某一元素
        [set2 removeObject:@"2"];
        NSLog(@"%@",set2);
    //赋值
        [set1 setSet:set2];
        NSLog(@"%@",set1);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/haitong-0311/p/5121634.html