I am currently writing Swift 3 code in Xcode 8.
When using oldValue
and newValue
default parameters inside the willSet
and didSet
blocks, I am getting "unresolved identifier"
compiler error.
I have a very basic code as below
var vc:UIViewController? {
willSet {
print("Old value is \(oldValue)")
}
didSet(viewController) {
print("New value is \(newValue)")
}
}
Apple Documentation for Swift 3 still seems to support these feature. I hope I am not missing anything here?
You didn't try to initialize the variable with a new object by which you can set your clojure:
You can also use
vc
:The special variable
newValue
only works withinwillSet
, whileoldValue
only works withindidSet
.The property as referenced by its name (in this example
vc
) is still bound to the old value withinwillSet
and is bound to the new value withindidSet
.