arkilis
10/14/2017 - 1:20 AM

Swift Set

Swift Set

// Create mutable set
var fooSet : Set<String> = ["a", "b", "c"]
//var fooSet : Set = ["a", "b", "c", "c"]
fooSet.insert("d")
fooSet.remove("a")
print(fooSet)


// Create immutable set
let fooImmutableSet : Set = ["a", "b", "c"]
print(fooImmutableSet)



// Commone methods for both mutable and immutable set
// 1. Size
print(fooSet.count)

// 2. First and Last element
print(fooSet.first!)
//print(fooSet.last!)  // ERROR there is no last for set

// 3. Existence
print(fooSet.contains("b"))