title: Where should I add and remove observer in UICollectionViewCell?
body: <p>There is something I am missing in my understanding of UICollectionViewCell lifecycle. </p>
  
  <p>When UICollectionViewCell is created and configured I add observer on one of its properties </p>
  
  <pre><code>func setCellDetails(someDetails:SomeObject)
  {
      ...
      self.someProperty.addObserver(self, forKeyPath: "objectProperty", options: .New, context: nil)
      ...
  }
  </code></pre>
  
  <p>I remove the observer on <code>prepareForReuse</code></p>
  
  <pre><code>override func prepareForReuse()
  {
      super.prepareForReuse()
      self.someProperty.removeObserver(self, forKeyPath: "objectProperty")
  }
  </code></pre>
  
  <p>But then when I am jumping between tabs of the application and influence the <code>objectProperty</code> the cell is not effected. 
  I debugged the code and found that when I am changing the tabs, prepareForReuse of the cell is called so the observer is removed and it never added back because cell setup function is not called. So maybe I should add or remove the observer in other functions? </p>
  
  <hr>
  
  <p>I tried to put the <code>removeObserver</code> in <code>deinit</code> and it crashes with the following error:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: 'An instance 0x12eb89dd0
    of class ObservedObject was deallocated while key value observers were
    still registered with it. Current observation info:
    NSKeyValueObservationInfo NSKeyValueObservance
    Observer: .. Key path: objectProperty</p>
  </blockquote>
  
  <p>I thought maybe not to put removeObserver in anyplace. It produced the same error.</p>
  
  <p>What should I do? Where should I put it? </p>