Skip to content

Instantly share code, notes, and snippets.

@garohussenjian
Last active January 6, 2018 20:06
Show Gist options
  • Save garohussenjian/0b6677d3e4eef9ccf5934b897df491c1 to your computer and use it in GitHub Desktop.
Save garohussenjian/0b6677d3e4eef9ccf5934b897df491c1 to your computer and use it in GitHub Desktop.
Property observer unexpectedly firing?
// 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