Created
October 18, 2019 18:48
-
-
Save cobbal/5b93442e8b5487a119a9c4d9f9711975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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