<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CALayer/animation(forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)animationForKey:"
  },
  "title" : "animation(forKey:)"
}
-->

# animation(forKey:)

Returns the animation object with the specified identifier.

```
func animation(forKey key: String) -> CAAnimation?
```

## Parameters

`key`

A string that specifies the identifier of the animation. This string corresponds to the identifier string you passed to the [`add(_:forKey:)`](/documentation/QuartzCore/CALayer/add(_:forKey:)) method.

## Return Value

The animation object matching the identifier, or `nil` if no such animation exists.

## Discussion

Use this method to retrieve only animation objects already associated with a layer. Modifying any properties of the returned object results in undefined behavior.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)