int main(int argc, const char * argv[]) {
@autoreleasepool {
//1、创建可变set集合
NSMutableSet *set1=[NSMutableSet set];
NSMutableSet *set2=[NSMutableSet setWithObjects:@"1",@"2", nil];
NSMutableSet *set3=[NSMutableSet setWithObjects:@"a",@"2",@"3", nil];
NSMutableSet *set4=[NSMutableSet setWithObjects:@"1",@"3", nil];
NSMutableSet *set5=[NSMutableSet setWithObjects:@"1",@"3",@"b",@"c", nil];
//2、集合2中的元素减去集合3中的元素
[set2 minusSet:set3];
NSLog(@"%@",set2);
//3、求两个集合的交集
[set3 intersectSet:set4];
NSLog(@"%@",set3);
//4、求两个集合的并集
[set2 unionSet:set3];
NSLog(@"%@",set2);
//5、移除集合中的对象
[set2 removeObject:@"1"];//移除一个
NSLog(@"%@",set2);
[set2 removeAllObjects];
NSLog(@"%@",set2);
//6、集合复制
[set2 setSet:set5];
NSLog(@"%@",set2);
}
return 0;
}
时间: 2024-10-14 20:54:42