title: When to unregister KVO observation of Operation isFinished
body: <p>In this simple code (Xcode 8.3), I create an Operation subclass instance, register for KVO observation of its <code>isFinished</code> property, and launch the operation by adding it to my queue:</p>
  
  <pre><code>class MyOperation : Operation {
      override func main() {
          print("starting")
          print("finishing")
      }
  }
  
  class ViewController: UIViewController {
      let q = OperationQueue()
      override func viewDidLoad() {
          super.viewDidLoad()
          let op = MyOperation()
          op.addObserver(self, forKeyPath: #keyPath(MyOperation.isFinished), options: [], context: nil)
          self.q.addOperation(op)
      }
  
      override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
          print("Observed \(keyPath)")
          if let op = object as? Operation {
              op.removeObserver(self, forKeyPath: #keyPath(MyOperation.isFinished))
          }
      }
  }
  </code></pre>
  
  <p>As you can see, I have an implementation of <code>observeValue(forKeyPath...</code>, of course, and my plan was to call <code>removeObserver(forKeyPath...</code> there. </p>
  
  <p>The problem is that my app crashes with "MyOperation was deallocated while key value observers were still registered with it". We print "starting" and "finishing" but we never print "Observed"; the operation goes out of existence <em>before</em> I get my KVO notification.</p>
  
  <p>This seems like a catch-22. If I can't remove the observer by observing <code>isFinished</code>, when am I supposed to do it? [I can work around this issue by adding to MyOperation my own KVO-observable property that I set at the end of <code>main</code>. But the notion that I should have to do this is very odd; isn't this exactly why <code>isFinished</code> is observable, so that I can do what I'm trying to here?]</p>