1. Create a collection (unordered and non-repeatable)
(1) Create an empty collection
var a=set<int> ()//[]
(2) Create a collection
var a:set=[1,2,3]//[2,3,1]
2. Insert in the middle of the collection
var A:set=[1,2,3]a.insert (4)//[2,4,3,1]
3, set (remove) Delete
var a:set=[1,2,3]a.remove (2)//[3,1]
4. Whether the set (contains) has this element
var a:set=[1,2,3]print (A.contains (2))//true
5. Set conversion (sorted) to an array
var a:set=[1,2,3]var b=a.sorted ()//[1,2,3]
6. Special application of Set, subset, parent set, intersection, set, complement, difference set
(1) Intersection
Let X:set=[1,2,3]let y:set=[3,4,5]let z=x.intersection (y)//[3]
(2) Difference set
var x:set=[1,2,3]var y:set=[3,4,5]x.subtract (y) //modify itself x,[2,1]
(3) and set
var x:set=[1,2,3]var y:set=[3,4,5]var z=x.union (y)//[3,4,1,5,2]
(4) Complementary set
var x:set=[1,2,3]var y:set=[3,4,5]var z=x.symmetricdifference (y) //[5,2,4,1]
(5) determining whether a subset
var x:set=[3,4,5]var y:set=[3,4,5]var Z=x.issubset (of:y)//x is not a subset of Y, Truevar q=x.isstrictsubset (of:y)//strict subset, False
(6) Determine if the parent set
var x:set=[3,4,5]var y:set=[3,4,5]var Z=x.issuperset (of:y)//x is not a parent set of Y, Truevar q=x.isstrictsuperset (of:y)//strict parent set, False
(7) Determine if there is an intersection
var x:set=[3]var y:set=[3,4,5]var z=x.isdisjoint (with:y)//false
Swift, Collection