Swift Set
Main Idea
A complex data type that holds multiple piece of data. No duplicates and no order
let people = Set(["Denzel Washington", "Tom Cruise", "Nicolas Cage", "Samuel L Jackson"])
print(people)
// explict
var people = Set<String>()
people.insert("Denzel Washington")
people.insert("Tom Cruise")
people.insert("Nicolas Cage")
people.insert("Samuel L Jackson")
// .insert because we don't add on to the ordered list, it can go anywhere so insert
// .contains() is O(1) vs O(n) for arrays
// .count get number of items
// .sorted() returns sorted array of set.
Notes mentioning this note
Swift Complex Data Types
Main Idea
A complex data type holds multiple value at a time, grouping data together