What does an “array” do?
Stores values of the same type in an ordered list.
What does a “set” do?
It stores distinct values of the same type in a collection with no defined ordering.
When is a good time to use a “set” instead of an array? (List two examples)
2. When you need to ensure that an item appears only once.
2. Provide an example
A type must be _____ in order to be stored in a set.
hashable (The type must provide a way to compute a “hash value” for itself)
What Swift types are hashable by default? (List 2)
Data types that are hashable can be used as 1. ____ or 2. ______.
2. Dictionary key types.
Create an empty set of a certain type using the initializer syntax
var setName = Set( )
Initialize a set with an array literal
var arrayLiteralSet: Set = [“ItemOne”, “ItemTwo”, “ItemThree”]
Initialize a set with an array literal using Swift’s type inference to assume the type
var arrayLiteralSet: Set = ["ItemOne", "ItemTwo", "ItemThree"] //Because all values are same type swift can infer that Set is correct.
You access and modify a set through it’s 1)_____ and 2)_____.
2. Properties
You can add a new item into a set by calling the set’s ______ method.
insert(_: )
You can check whether a sets count property is equal to 0 by using the ___ property.
isEmpty
Use isEmpty in an if statement
if setName.isEmpty {
instructions if true
} else {
instructions if false
}You can remove an item from a set by calling the set’s _____ method
remove(_: )
All items in a set can be removed with its _____ method.
removeAll( )
To check whether a set contains a particular item, use the _____ method.
contains(_: )
You can iterate over the values in a set with a _____ loop
for-in
Swift’s set type does not have ____ _____.
Defined ordering
To iterate over the values of a set in a specific order, use the _____ method.
sorted( )
What will happen if you use a sets sorted( ) method on it?
It will return the set’s elements as an array sorted using the < operator.
Use the 1. _____ method to create a new set with only the values common to both sets.
Use the 1. ______ method to create a new set with values in either set, but not both.
Use the 1. ______ method to create a new set with all the values in both sets