2/100 Days of SwiftUI

Follow my instagram @parttimedeveloper_ for more dev tips, tricks, and notes!

Arrays

// 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]
pets[1] // Dobby Wilson

Sets

let westNHLTeams = Set(["Ducks", "Blackhawks", "Coyotes", "Avalanche", "Flames", "Stars", "Oilers", "Wild", "Kings", "Predators", "Sharks", "Blues", "Canucks", "Jets", "Golden Knights"])
// flames and avalanche are duplicated
let westNHLTwo = Set(["Ducks", "Blackhawks", "Coyotes", "Avalanche", "Avalanche", "Flames", "Flames", "Stars", "Oilers", "Wild", "Kings", "Predators", "Sharks", "Blues", "Canucks", "Jets", "Golden Knights"])
print(westNHLTeams)
// ["Blackhawks", "Predators", "Blues", "Stars", "Kings",
// "Avalanche", "Golden Knights", "Coyotes", "Flames",
// "Sharks", "Oilers", "Wild", "Ducks", "Canucks", "Jets"]
print(westNHLTeamsTwo)
// ["Blackhawks", "Predators", "Blues", "Stars", "Kings",
// "Avalanche", "Golden Knights", "Coyotes", "Flames",
// "Sharks", "Oilers", "Wild", "Ducks", "Canucks", "Jets"]

Tuples

var name = (first: "Taylor", second: "Swift")name.0
name.first

When to use each?

Dictionaries

let captains = [
"penguins": "Crosby",
"wild": "Spurgeon",
"sharks": "Couture"
]
captains["penguins"] // Crosby
captains["ducks"] // nil
let captains = [
"penguins": "Crosby",
"wild": "Spurgeon",
"sharks": "Couture",
"ducks": "unknown"
]
captains["penguins"] // Crosby
captains["ducks"] // unknown

Empty Collections

var emptyArray: [String]
var emptyDictionary: [String: Int]
var emptySet = Set<String>()

Enumerations (enums)

let result1 = "failure"
let result2 = "failed"
enum Result {
case failure
case success
}
let result3 = Result.failure
enum AppleProducts {
case iPhone(generation: String)
case laptop(model: String)
}
let maegansPhone = AppleProducts.iPhone(generation: "12 Pro Max")
let katiesLaptop = AppleProducts.laptop(model: "MacBook Pro")
enum Planet: Int {
case mercury
case venus
case earth
case mars
}
print(Planet.earth.rawValue) // 2
enum Planet: Int {
case mercury = 1
case venus
case earth
case mars
}
print(Planet.earth.rawValue) // 3

A non-binary person that develops iOS apps as a part time gig. I share my knowledge in posts and on my twitch streams, https://twitch.tv/maeganwilson_

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store