OC NSSet
OC NSSet
数组的特点: 有序的
Set的特点: 无序的,存储元素无重复(例:set中有两个元素'a' 输出时只输出一个a)
NSSet初始化
NSSet * set = [[NSSet alloc] initWithObjects:@"a",@"b",@"c", nil];
NSSet * set1 = [NSSet setWithObjects:@"z",@"x",@"c", nil];
NSSet * set2 = [NSSet setWithArray:array];
获取NSSet中任意对象
[set2 anyObject]
是否包含某对象
[set2 containsObject:@"w"]
是否有相同元素
[set intersectsSet:set2]
NSMutableSet用法
NSMutableSet初始化
NSMutableSet * set = [[NSMutableSet alloc] initWithCapacity:0];
追加删除和NSMutableArray一样
取两个NSSet的并集
[set unionSet:set2]
NSSet减去一样的元素
[set minusSet:set2]
取两个NSSet的交集
[set intersectSet:set2]