#26: Calling didSet
Question
// Swift Quiz
— objc.io (@objcio) August 15, 2019
struct A {
static var x = "Advanced"
var xBuzz: String {
didSet {
A.x = oldValue
}
}
}
let obj = A(xBuzz: "Swift")
// What's the value of A.x?
Solution
Solution: Advanced
— objc.io (@objcio) August 16, 2019
In an initializer, `didSet` is not called.
Only once we set `obj.xBuzz` will `didSet` be called, and the value changes to the previous value ("Swift").https://t.co/s7500CWmAg