1.创建集合对象
(1)便利构造器
NSSet *set1 = [NSSet setWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
NSLog(@"%@",set1);
(2)alloc初始化构造方法
NSSet *set2 = [[NSSet alloc]initWithObjects:@"1",@"2",@"3",
@"4" ,@"5",@"3",nil];
NSLog(@"%@",set2);
2.获取元素个数
NSLog(@"count = %ld",[set1 count]);
3.获取集合中的某个元素(取的是对它来说最方便的那个)
NSString *str1 = [set1 anyObject];
NSLog(@"%@",str1);
NSString *str2 = [set1 anyObject];
NSLog(@"%@",str2);
NSString *str3 = [set1 anyObject];
NSLog(@"%@",str3);
NSString *str4 = [set1 anyObject];
NSLog(@"%@",str4);
4.判断集合中是否存在某个对象
BOOL isContain = [set1 containsObject:@"3"];
NSLog(@"isContain = %d",isContain);
可变集合
NSMutableSet *set3 = [NSMutableSet setWithObjects:@"1",@"2",@"3", nil];
NSLog(@"%@",set3);
1.添加元素
[set3 addObject:@"6"];
NSLog(@"%@",set3);
2.移除元素
[set3 removeObject:@"6"];
NSLog(@"%@",set3);