
通过学习Swift 4.0,总结一下Swift相对于Objective-C的一些新特征。
Set,一组无序变量的组合,和OC中NSSet类似。
- 定义一个Set
1
2
3var tmpSet : Set = [1,2,3,4]
Set是无序的,所以无法使用 .语法 tmpSet.0进行取值
-
添加元素 / 删除元素
1
2tmpSet.insert(6)
tmpSet.remove(6) -
两组Set交集、子集、补集等
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16//交集
tmpSet.intersection(tmpSet2)
//差集
tmpSet.subtract(tmpSet2)
//并集
tmpSet.union(tmpSet2)
//补集
tmpSet.symmetricDifference(tmpSet2)
//是否相等
tmpSet == tmpSet2
//子集 (是否包含)
tmpSet.isSubset(of: tmpSet2)
//严格子集
tmpSet.isStrictSubset(of: tmpSet2)
//无交集
tmpSet.isDisjoint(with: tmpSet2)




近期评论