为什么这段代码会在初始化时触发 didSet
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()
任何想法?它不应该触发 didSet 吗?有人帮忙!
更新:我的观点是这样,
testSet()
并且_value = false
正在做同样的事情,但是testSet()
在外面init()
,所以testSet()
会触发didSet
而_value = false
不是。为什么?!
我想,这不是导致“didSet”的可选类型或其他原因。