Member-only story

2/100 Days of SwiftUI

Jay Wilson
4 min readJan 4, 2021
Follow my instagram @parttimedeveloper_ for more dev tips, tricks, and notes!

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.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jay Wilson
Jay Wilson

Written by Jay Wilson

I like to solve problems using Swift, make YouTube videos, and take photos. I also really enjoy a good cup of coffee.

No responses yet

Write a response