Relationship between CABasicAnimation's KeyPath and a CALayer's action event

I have a CALayer and I'd like to animate a property on it. But, the property that triggers the animation change is different to the one that is being changed. A basic example of what I'm trying to do is below. I'm trying to create an animation on count by changing triggerProperty. This example is simplified (in my project, the triggerProperty is not an Int, but a more complex non-animatable type. So, I'm trying to animate it by creating animations for some of it's properties that can be matched to CABasicAnimation - and rendering a version of that class based on the interpolated values).

@objc
class AnimatableLayer: CALayer {
    @NSManaged var triggerProperty: Int
    @NSManaged var count: Int

    override init() {
        super.init()
        triggerProperty = 1
        setNeedsDisplay()
    }


    override init(layer: Any) {
        super.init(layer: layer)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override class func needsDisplay(forKey key: String) -> Bool {
        return key == String(keypath: \AnimatableLayer.triggerProperty) || super.needsDisplay(forKey: key)
    }

    override func action(forKey event: String) -> (any CAAction)? {
        if event == String(keypath: \AnimatableLayer.triggerProperty) {
            if let presentation = self.presentation() {
                let keyPath = String(keypath: \AnimatableLayer.count)
                let animation = CABasicAnimation(keyPath: keyPath)
                animation.duration = 2.0
                animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
                animation.fromValue = presentation.count
                animation.toValue = 10

                return animation
            }
        }

        return super.action(forKey: event)
    }

    override func draw(in ctx: CGContext) {
        print("draw")
        NSGraphicsContext.saveGraphicsState()
        let nsctx = NSGraphicsContext(cgContext: ctx, flipped: true) // create NSGraphicsContext
        NSGraphicsContext.current = nsctx // set current context

        let renderText = NSAttributedString(string: "\(self.presentation()?.count ?? self.count)", attributes: [.font: NSFont.systemFont(ofSize: 30)])
        renderText.draw(in: bounds)
        NSGraphicsContext.restoreGraphicsState()
    }

    func animate() {
        print("animate")
        self.triggerProperty = 10
    }
}

With this code, the animation isn't triggered. It seems to get triggered only if the animation's keypath matches the one on the event (in the action func).

Is it possible to do something like this?

Relationship between CABasicAnimation's KeyPath and a CALayer's action event
 
 
Q