November 2016
Intermediate to advanced
480 pages
14h 42m
English
Value and reference types behave differently when they are constants. Create a new struct called Pantheon so that you have a value type of your own to work with.
Listing 18.7 Making the Greek Pantheon
...
class GreekGod {
var name: String
init(name: String) {
self.name = name
}
}
let hecate = GreekGod(name: "Hecate")
let anotherHecate = hecate
anotherHecate.name = "AnotherHecate"
anotherHecate.name
hecate.name
struct Pantheon {
var chiefGod: GreekGod
}
The new struct represents the Greek pantheon.
It has one stored property to reflect the foremost god in the pantheon.
Greek gods are always squabbling, so you made this property mutable with var.
Make a new instance of Pantheon with hecate ...
Read now
Unlock full access