Sets

CREATING SETS

let setOne: Set

let someArray = [1, 2, 3, 1]

var someSet: Set = [1, 2, 3, 1]

print(someSet)
// > [2, 3, 1]

ACCESSING ELEMENTS

print(someSet.contains(1))
// > true
print(someSet.contains(4))
// > false

ADDING & REMOVING ELEMENTS

someSet.insert(5)

let removedElement = someSet.remove(1)
print(removedElement!)
// > 1

你可能感兴趣的:(Sets)