I have a box that the user is able to pan around. For that, I add an observer to check if it's center has changed:
self.boxView!.addObserver(self, forKeyPath: "center", options: .old, context: &BoxCenterContext)
This gets added after an animation that presents the box.
When the box dismisses, I remove it as this:
self.boxView!.removeObserver(self, forKeyPath: "center", context: &BoxCenterContext)
Issue
There is a possibility of the user being able to dismiss the box before box presentation has been completed, ie. before the KVO is added.
When that happens, the app crashes trying to remove a KVO that does not exist.
Question
Is there a way to check for existence of KVO (before trying to remove)?