Skip to content

Instantly share code, notes, and snippets.

@cobbal
Created October 18, 2019 18:48
Show Gist options
  • Save cobbal/5b93442e8b5487a119a9c4d9f9711975 to your computer and use it in GitHub Desktop.
Save cobbal/5b93442e8b5487a119a9c4d9f9711975 to your computer and use it in GitHub Desktop.
class A {
private var underlying: Int = 0
open var x: Int {
set {
print("A.set \(newValue)")
underlying = newValue
}
get { underlying }
}
}
class B: A {
override open var x: Int {
didSet {
print("B.didSet \(oldValue) -> \(x)")
}
}
}
class C: B {
override open var x: Int {
didSet {
print("C.didSet \(oldValue) -> \(x)")
}
}
}
C().x = 4
// A.set 4
// B.didSet 0 -> 4
// C.didSet 0 -> 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment