swift – 覆盖didSet
发布时间:2020-12-14 04:35:37 所属栏目:百科 来源:网络整理
导读:我想覆盖属性观察者并调用“super.didSet”.那可能吗? class Foo { var name: String = "" { didSet { print("name has been set") } }}class Bar: Foo { override var name: String = "" { didSet { print("print this first") // print the line set in t
我想覆盖属性观察者并调用“super.didSet”.那可能吗?
class Foo { var name: String = "" { didSet { print("name has been set") } } } class Bar: Foo { override var name: String = "" { didSet { print("print this first") // print the line set in the superclass } } } 解决方法
我已经在游乐场尝试了你的代码并得到了错误
所以我只是从orverriding变量中删除了=“”.如下: class Foo { var name: String = "" { didSet { print("name has been set") } } } class Bar: Foo { override var name: String { didSet { print("print this first") // print the line set in the superclass } } } let bar = Bar() bar.name = "name" 这就是我在康复中所得到的: name has been set print this first (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |