title: how to override func observeValueForKeyPath on Swift 5.2- Xcode Version 11.5
body: <p>I'm trying porting <a href="https://developer.apple.com/swift/blog/?id=35" rel="nofollow noreferrer">this interactive playground</a> on <strong>Swift 5.2</strong> - <strong>Xcode Version 11.5</strong>  but I still got <code>Method does not override any method from its superclass</code> and I still haven't figured out how to set this method signature. The class I'm working on extends <code>UIView</code> from <code>UIKit</code>.</p>
  <p>I looked with <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>O</kbd> the header <code>NSKeyValueObserving.h</code> and found:</p>
  <pre><code>- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary&lt;NSKeyValueChangeKey, id&gt; *)change context:(nullable void *)context;
  </code></pre>
  <p>Since now I've tried without success:</p>
  <pre><code>    public override func observeValueForKeyPath(keyPath: String!, 
      ofObject object: AnyObject!, 
      change: [String : AnyObject]!, 
      context: UnsafeMutablePointer&lt;()&gt;)
      
      public override func observeValueForKeyPath(keyPath: String!, 
      ofObject object: AnyObject!, 
      change: [String : AnyObject]!, 
      context: UnsafeMutableRawPointer)
      
      public override func observeValueForKeyPath(keyPath: String!, 
      of object: Any?, 
      change: [NSKeyValueChangeKey : Any]?, 
      context: UnsafeMutableRawPointer?)
  </code></pre>
  <h3>more info about the class I'm working on</h3>
  <pre><code>import UIKit
  import XCPlayground
  
  public class NewtonsCradle: UIView  {
      
      private let colors: [UIColor]
      private var balls: [UIView] = []
      
      private var animator: UIDynamicAnimator?
      private var ballsToAttachmentBehaviors: [UIView:UIAttachmentBehavior] = [:]
      private var snapBehavior: UISnapBehavior?
      
      public let collisionBehavior: UICollisionBehavior
      public let gravityBehavior: UIGravityBehavior
      public let itemBehavior: UIDynamicItemBehavior
      
      public init(colors: [UIColor]) {
          self.colors = colors
          collisionBehavior = UICollisionBehavior(items: [])
          gravityBehavior = UIGravityBehavior(items: [])
          itemBehavior = UIDynamicItemBehavior(items: [])
      
          super.init(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
          backgroundColor = UIColor.white
          animator = UIDynamicAnimator(referenceView: self)
          animator?.addBehavior(collisionBehavior)
          animator?.addBehavior(gravityBehavior)
          animator?.addBehavior(itemBehavior)
          
          createBallViews()
      }
      
      public required init?(coder aDecoder: NSCoder) {
          fatalError(&quot;init(coder:) has not been implemented&quot;)
      }
      
      deinit {
          for ball in balls {
              ball.removeObserver(self, forKeyPath: &quot;center&quot;)
          }
      }
  
     /* SNIP */
  
     public override func observeValueForKeyPath(keyPath: String!, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
          if (keyPath == &quot;center&quot;) {
              setNeedsDisplay()
          }
      }
    /* SNIP */
  </code></pre>