Member-only story
2/100 Days of SwiftUI

Here are day 2’s notes! Have fun and if you have any questions or notice there’s an issue, let me know on Twitter, Instagram, or in the comments.
Today’s Topics
- Arrays
- Tuples
- Dictionaries
- Sets
- Enums
Arrays
Arrays are collections of data in a specific order and are stored as a single value.
Example of an Array with my pets
// values for array
let thorgi = "Thorgi Wilson"
let dobby = "Dobby Wilson"
let cairo = "Cairo Wilson"
let sydney = "Sydney Wilson"// creates the array
let pets = [thorgi, dobby, cairo, sydney]
To retrieve a value from the array, the position of the value is needed. Note, the positions for array start at 0.
Example: get the value of dobby
pets[1] // Dobby Wilson
If trying to get a value from a position that doesn’t exist, then Swift will crash.
If wanting to give a type to the array, put the type annotation in brackets. The image below shows that calling pets[6]
gives an index out of range error since there are only 4 positions in pets
.