title: How to observe changes, and store previous values, of an inherited object's property?
body: <p><strong>Set Up:</strong></p>
  <p>I'm subclassing <code>SKSpriteNode()</code> to create a custom subclass called <code>SubNode()</code>.</p>
  <p>The SKSPriteNode() class has a property called <code>physicsBody</code> which stores a <code>SKPhysicsBody()</code> object. <code>SKPhysicsBody</code> has a property called 'velocity' that is a <code>CGVector()</code></p>
  <p><strong>Goal:</strong></p>
  <p>In my subclass I'd like to have a variable which always keeps the previous <code>CGVector()</code>. Meaning as soon as I call <code>subNode.physicsBody?.velocity = CGVector(dx: 10, dy: 10)</code> for example. <code>subNode.previousVelocity</code> should be set to the previous <code>subNode.physicsBody?.velocity</code> value.</p>
  <p><strong>Issue</strong></p>
  <p>If <code>velocity</code> would just be an inherited property of the superclass I could just <code>override</code> the property and attach an <code>didSet</code> observer. But since <code>velocity</code> is a property of <code>SKPhysicsBody()</code> and the  <code>SKPhysicsBody()</code> object doesn't change when one of its properties changes, <code>didSet</code> doesn't get triggered and I'm unable to listen to its changes.</p>
  <p>Please ask for more clarification if my explanation is unclear.</p>
  <p><strong>My subclass:</strong></p>
  <pre><code>class SubNode: SKSpriteNode {
      
      var previousVelocity: CGVector = .zero
  
      // This doesn't get triggered because the physiceBody object doesn't change when one of its properties changes.
      override var physicsBody: SKPhysicsBody? {
          didSet {
              previousVelocity = oldValue?.velocity
          }
      }
      
      // If velocity would be a property of the superclass, this would trigger.
      override var velocity: CGVector {
          didSet {
              previousVelocity = oldValue
          }
      }
  }
  </code></pre>
  <p><strong>Creating the object subNode from the SubNode() subclass, setting the physics body and then the velocity&quot;</strong></p>
  <pre><code>let subNode = SubNode()
  subNode.physicsBody = SKPhysicsBody()
  subNode.physicsBody?.velocity = CGVector(dx: 10, dy: 10)
  subNode.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
  //should be true: subnode.previousVelocity == CGVector(dx: 10, dy: 10)
  </code></pre>