"oldValue"和"newValue"无法识别willSet/didSet中的默认参数名称 [英] "oldValue" and "newValue" default parameters names inside willSet / didSet unrecognized

查看:82
本文介绍了"oldValue"和"newValue"无法识别willSet/didSet中的默认参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用Xcode 8编写Swift 3代码.

I am currently writing Swift 3 code in Xcode 8.

willSetdidSet块中使用oldValuenewValue默认参数时,出现"unresolved identifier"编译器错误.

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?

推荐答案

您还可以使用vc:

var vc:UIViewController? {
    willSet {
        print("New value is \(newValue) and old is \(vc)")
    }
    didSet {
        print("Old value is \(oldValue) and new is \(vc)")
    }
}

这篇关于"oldValue"和"newValue"无法识别willSet/didSet中的默认参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆