Last active
January 6, 2018 20:06
-
-
Save garohussenjian/0b6677d3e4eef9ccf5934b897df491c1 to your computer and use it in GitHub Desktop.
Property observer unexpectedly firing?
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
// Property observer unexpectedly firing? | |
protocol MyProtocol { | |
var value: String { get set } | |
} | |
class MyClass: MyProtocol { | |
var value: String = "Value" | |
} | |
class MyContext { | |
var object: MyProtocol { | |
didSet { print(object.value) } | |
} | |
init(object: MyProtocol) { | |
self.object = object | |
} | |
} | |
let reference = MyClass() | |
let context = MyContext(object: reference) | |
reference.value = "This should't fire (and doesn't)" // ✅ | |
context.object.value = "This should't fire (but does?)" // ⚠️ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment