子类和父类的计算属性同时存在didSet、willSet
时,调用顺序探索
class GitArtOS {
var content: String = "我是老爹" {
willSet {
print("老爹willSet newValue = \(newValue) ")
}
didSet {
print("老爹didSet oldValue = \(oldValue) ")
}
}
}
class SubArtOS: GitArtOS {
override var content: String {
willSet {
print("儿子willSet newValue = \(newValue) ")
}
didSet {
print("儿子didSet oldValue = \(oldValue) ")
}
}
}
var subson = SubArtOS()
subson.content = "子类和父类的计算属性同时存在didSet、willSet时,调用顺序探索"
执行顺序如下:
儿子willSet newValue = 子类和父类的计算属性同时存在didSet、willSet时,调用顺序探索
老爹willSet newValue = 子类和父类的计算属性同时存在didSet、willSet时,调用顺序探索
老爹didSet oldValue = 我是老爹
儿子didSet oldValue = 我是老爹
Program ended with exit code: 0
网友评论