Let me use a different example.
struct Programmer {
let name: String
var distanceFromWall = 30
var screenDistanceFromWall = 20
var distanceFromScreen: Int {
distanceFromWall - screenDistanceFromWall
}
}
You might create a programmer object and see that, by default, the programmer is a distance of 10 from her computer's screen. If you change her distance from the wall to 40, she'll be a distance of 20 from her screen. You compute this value each time you want to know the distance.
But WHAT IF you wanted to specify the distance between the programmer and her screen? One way would be to move the monitor, or reseat the programmer. However, with a setter, you can give the desired value to the computed property. Then you let the computed property either (1) move the programmer or (2) move the monitor. That's your business to decide!
In this case you are "writing to" the computed property.
struct Programmer {
let name: String
var distanceFromWall = 30
var screenDistanceFromWall = 20
var distanceFromScreen: Int {
get {
distanceFromWall - screenDistanceFromWall // no change here
}
set {
// easier to move the programmer, than move the screen!
// Here you change the programmer's distance to the wall
// so that the programmer is now "newValue" distance from the monitor.
distanceFromWall = screenDistanceFromWall + newValue // moving the programmer!
}
}
}
You are correct however. In the inital example, you can just change the vacation variables. But this is not the concept that @twostraws was teaching in this lesson.