本文介绍了"oldValue"和"newValue"无法识别willSet/didSet中的默认参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在用Xcode 8编写Swift 3代码.
I am currently writing Swift 3 code in Xcode 8.
在willSet
和didSet
块中使用oldValue
和newValue
默认参数时,出现"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文档似乎仍支持这些功能.我希望我在这里不丢失任何东西吗?
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中的默认参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!