#34: Initialization and didSet
Question
// Swift Quiz
— objc.io (@objcio) October 16, 2019
struct Point: Equatable {
var x: Int
}
struct X {
var point: Point {
didSet {
point.x = 0
}
}
}
let y = Point(x: 5)
var p = X(point: y)
let result = p.point.x == y.x
// What's the value of result?
Solution
Solution: true
— objc.io (@objcio) October 17, 2019
The didSet does not get triggered in the initializer, so the p.point.x will have the original value of 5.https://t.co/s7500CWmAg