Classes and structs are different, but confusingly similar. With context and practical examples, I’m sure I’ll see more of a difference, but at this point, I’m not entirely sure when I’d use one vs the other.
I’m still very much itching for practical uses of this stuff – I’m getting pretty tired of writing code like this:
class Dog {
var name: String
var breed: String
init(name: String, breed: String) {
self.name = name
self.breed = breed
}
func makeNoise() {
print("Wooooof")
}
}
class Pug : Dog {
init(name: String) {
super.init(name: name, breed: "Pug")
}
override func makeNoise() {
print("Bark, bark, bark!")
}
}
let oliver = Pug(name: "Oliver")
oliver.makeNoise()
References
- Day 10 – https://www.hackingwithswift.com/100/swiftui/10
- Classes summary – https://www.hackingwithswift.com/sixty/8/8/classes-summary