100 Days of SwiftUI
2026-04-21
- Type Annotations (specifying rather than letting Swift infer)
So if these 3 lines are equivalent (make an empty array that will hold Strings)
var myvar: [String] = [String]()
var myvar: [String] = []
var myvar = [String]()when would you choose one over the other?
Listening more, it seems that it doesn’t really matter most of the time? Just as long as you don’t try to change the type of an object from say, String to Int (or more likely Int to Double)
Quiz - Type Annotations — 6/6
Checkpoint 2
the challenge is to create an array of strings, then write some code that prints the number of items in the array and also the number of unique items in the array.
PuzzleMy solution
var theArray = [String]()
theArray.append("Pink")
theArray.append("Red")
theArray.append("Pink")
theArray.append("Red")
theArray.append("Blue")
theArray.append("Yellow")
theArray.append("Green")
theArray.append("Orange")
theArray.count
// finds unique items
var theSet = Set(theArray)
theSet.count- My Excel kept getting in the way (COUNTUNIQUE) but the Swift Playground wouldn’t autocomplete it :lol: