Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/39559212/oldvalue-and-newvalue-default-parameters-names-inside-willset-didset-unrec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)")
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...