When should I remove observers? Error about deallocating objects before removing observers

Ah. You’re observing a TekkPoint object from a SomethingElse object, and the SomethingElse object is the one adding and removing the observers, correct? (That’s the normal way things are done; I’m just trying to clarify.) It looks like your TekkPoint object is being deallocated while the SomethingElse that’s observing it is still around. The SomethingElse … Read more

KVO – How to check if an object is an observer?

[…] is it possible to check if an object actually is observing that property? No. When dealing with KVO you should always have the following model in mind: When establishing an observation you are responsible for removing that exact observation. An observation is identified by its context—therefore, the context has to be unique. When receiving … Read more

Swift 4 approach for observeValue(forKeyPath:…)

Swift 4 introduced a family of concrete Key-Path types, a new Key-Path Expression to produce them and a new closure-based observe function available to classes that inherit NSObject. Using this new set of features, your particular example can now be expressed much more succinctly: self.observation = object.observe(\.keyPath) { [unowned self] object, change in self.someFunction() } … Read more