Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"oldValue" and "newValue" default parameters names inside willSet / didSet unrecognized

Tags:

ios

swift

swift3

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?

like image 248
Adithya Avatar asked Sep 18 '16 15:09

Adithya


People also ask

What is newValue in Swift?

In willSet Swift provides your code with a special value called newValue that contains what the new property value is going to be, and in didSet you are given oldValue to represent the previous value.

What is didSet in Swift?

didSet is called right after the data is stored and it has a default constant oldValue which shows the previous value that is overwritten.


1 Answers

You can also use vc:

var vc:UIViewController? {     willSet {         print("New value is \(newValue) and old is \(vc)")     }     didSet {         print("Old value is \(oldValue) and new is \(vc)")     } } 
like image 89
FranMowinckel Avatar answered Sep 19 '22 08:09

FranMowinckel