Why this code will trigger didSet when init
final public class TestDidSet {
static var _shared: TestDidSet! = TestDidSet()
func testA() { }
private var test = true {
didSet {
print("didSet test when initing!!!!!:\(test)")
}
}
private var _value: Bool! {
didSet {
print("didSet when initing!!!!!:\(_value)")
}
}
private init() {
testSet()
_value = false
test = false
}
private func testSet() {
_value = true
}
}
TestDidSet._shared.testA()
any idea? should it not trigger didSet? someone help!
update:
My point of view is this,
testSet()
and _value = false
is doing the same thing, but testSet()
is outside init()
, so testSet()
will trigger didSet
while _value = false
not. Why?!
It's not optional type or other reason, that cause 'didSet', I suppose.