         var gradientAnimation: CAKeyframeAnimation? = nil
         if fadeLength > 0.0 {
             // Remove any setup animation, but apply final values
-            if let finalColors = maskLayer?.animationForKey("setupFade")?.valueForKey("setupFade") as? [CGColorRef] {
+            if let setupAnim = maskLayer?.animationForKey("setupFade") as? CABasicAnimation, finalColors = setupAnim.toValue as? [CGColorRef] {
                 maskLayer?.colors = finalColors
             }
             maskLayer?.removeAnimationForKey("setupFade")

            colorAnimation.fillMode = kCAFillModeForwards
            colorAnimation.removedOnCompletion = false
            colorAnimation.delegate = self
            colorAnimation.setValue(adjustedColors, forKey: "setupFade")
            gradientMask.addAnimation(colorAnimation, forKey: "setupFade")
        } else {
            gradientMask.colors = adjustedColors

    
    override public func animationDidStop(anim: CAAnimation, finished flag: Bool) {
        if anim is GradientAnimation {
            if let setupAnim = maskLayer?.animationForKey("setupFade") as? CABasicAnimation, finalColors = setupAnim.toValue as? [CGColorRef] {
                maskLayer?.colors = finalColors
            }
            // Remove regardless, since we set removeOnCompletion = false
