Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...