title: CALayer.draw(in:) and CALayer.needsDisplay(forKey:) not called when expected, presentation layer unexpectedly nil
body: <p>I'm trying to implement a layer with implicitly animated properties, and I am seeing some very strange behavior. Here's a simple layer that demonstrates what I mean:</p>
  
  <pre><code>class CustomLayer: CALayer {
  
      override init() {
          super.init()
          implcitlyAnimatedProperty = 0.0000
          needsDisplayOnBoundsChange = true
      }
  
      override init(layer: Any) {
          super.init(layer: layer)
          implcitlyAnimatedProperty = (layer as! CustomLayer).implcitlyAnimatedProperty
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      }
  
      @NSManaged
      var implcitlyAnimatedProperty: CGFloat
  
      override func action(forKey event: String) -&gt; CAAction? {
          if event == "implcitlyAnimatedProperty" {
              let action = CABasicAnimation(keyPath: event)
              action.fromValue = presentation()?.value(forKey: event) ?? implcitlyAnimatedProperty
              return action
          } else {
              return super.action(forKey: event)
          }
      }
  
      override class func needsDisplay(forKey key: String) -&gt; Bool {
          if key == "implcitlyAnimatedProperty" {
              return true
          } else {
              return super.needsDisplay(forKey: key)
          }
      }
  
      override func draw(in ctx: CGContext) {
          if presentation() == nil {
              print("presentation is nil")
          }
          print(presentation()?.value(forKey: "implcitlyAnimatedProperty") ?? implcitlyAnimatedProperty)
      }
  }
  </code></pre>
  
  <p>I create an instance of <code>CustomLayer</code> and attempt to animate the property implicitly like this: </p>
  
  <pre><code>        let layer = CustomLayer()
          view.layer.addSublayer(layer) // I'm doing this in a view controller, when a button is pressed
          CATransaction.begin()
          CATransaction.setDisableActions(false)
          CATransaction.setAnimationDuration(10)
          layer.implcitlyAnimatedProperty = 10 // (1)
          layer.bounds = CGRect(x: 0, y: 0, width: 100, height: 100) // (2)
          CATransaction.commit()
  </code></pre>
  
  <p>The behavior that I'm seeing is as follows:</p>
  
  <ul>
  <li>With the code exactly as it's written above, the first time <code>draw(in:)</code> is called, <code>presentation()</code> returns <code>nil</code>, which, in my real app, makes the layer draw once with the final values from the model layer, which is an undesirable visual artifact. Otherwise, everything works as expected.</li>
  <li>With (2) commented out, <code>needsDisplay(forKey:)</code> is never called after the layer is created, and <code>draw(in:)</code> is never called. <code>action(forKey:)</code> <em>is</em> called, however. </li>
  </ul>
  
  <p>A common explanation for these functions not being called is that the layer has a delegate which is handling these calls on its behalf. But the layer's delegate is nil here, so that can't be what's happening. </p>
  
  <p>Why is this happening, and how can I fix it? </p>