---
title: "animation(forKey:)"
framework: quartzcore
role: symbol
role_heading: Instance Method
path: "quartzcore/calayer/animation(forkey:)"
---

# animation(forKey:)

Returns the animation object with the specified identifier.

## Declaration

```swift
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 doc://com.apple.quartzcore/documentation/QuartzCore/CALayer/add(_:forKey:) method.

## Return Value

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

## Discussion

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.

## See Also

### Layer animations

- [add(_:forKey:)](quartzcore/calayer/add(_:forkey:).md)
- [removeAllAnimations()](quartzcore/calayer/removeallanimations().md)
- [removeAnimation(forKey:)](quartzcore/calayer/removeanimation(forkey:).md)
- [animationKeys()](quartzcore/calayer/animationkeys().md)
