Extending the example from the other thread a little:
class Ref {
weak var obj: Obj? {
didSet { print(obj == nil ? "is nil" : "is not nil") }
}
}
class Obj {
weak var ref: Ref?
func unlink(from ref: Ref) {
print(ref.obj as Any)
}
deinit {
print("deinit")
ref.map(unlink(from:))
}
}
var obj: Obj? = Obj()
let ref = Ref()
obj?.ref = ref
ref.obj = obj
obj = nil
The result is:
is not nil
deinit
nil
Why don't we track and fire the didSet
observable when the object becomes nil? If there is a technical reason, so be it. However if not then it seems logical to me that the output should look like this:
is not nil
is nil
deinit
nil