// 集合 - 集合的元素具有唯一性
// 常用于判断交/并集等操作

/// 不可变集合

// 创建集合
// 如果有重复元素 只保留一个 eg;@"2", @"2"
NSSet *set = [NSSet setWithObjects:@"1",@"2" , @"3", @"4", nil];
// 集合中的元素个数
NSLog(@"%ld", set.count);
// 获取"某个"元素
// 获取哪个元素由系统决定
NSLog(@"%@", [set anyObject]);
// 是否包含
// 返回值为BOOL类型
NSLog(@"%d", [set containsObject:@"2"]);

/// 可变集合

NSMutableSet *mSet = [NSMutableSet setWithObjects:@"a", @"b", @"c", @"d", nil];
NSLog(@"%ld", mSet.count);
NSMutableSet *mset2 = [NSMutableSet setWithObjects:@"1", @"2", @"3", nil];
// 合并
// 将两个集合中的元素合并 合并之后的元素相同的话 只保留一个
[mSet unionSet:mset2];

// 交集
// 取两个集合中相同的元素
[mSet intersectSet:mset2];

// 添加元素
[mSet addObject:@"10"];
// 删除元素
[mSet removeObject:@"10"];
NSLog(@"%@", mSet);

// 元素依然具有唯一性 但是可以判断重复的元素个数
NSCountedSet *setC = [[NSCountedSet alloc]initWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
NSLog(@"%ld", setC.count);
// 判断9 重复的字符串(元素个数)有几个
NSLog(@"%ld", [setC countForObject:@"9"]);

// 集合的快速枚举
for (NSString *str in set) {
    NSLog(@"%@", str);
}

// 遍历数组 - 得到数组中的元素
// 遍历字典 - 得到字典中的Key!!!
// 遍历集合 - 得到集合中的元素
// 注意 forin中不可以改变(删除/添加等等操作)被遍历的collection(数组/字典/集合)

// for (<#type *object#> in <#collection#>) {
// <#statements#>
// }

屏幕快照 2016-01-07 下午4.38.31.png
屏幕快照 2016-01-07 下午4.38.51.png
屏幕快照 2016-01-07 下午4.39.55.png