<!--
{
  "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/add(_:forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CALayer(im)addAnimation:forKey:"
  },
  "title" : "add(_:forKey:)"
}
-->

# add(_:forKey:)

Add the specified animation object to the layer’s render tree.

```
func add(_ anim: CAAnimation, forKey key: String?)
```

## Parameters

`anim`

The animation to be added to the render tree. This object is copied by the render tree, not referenced. Therefore, subsequent modifications to the object are not propagated into the render tree.

`key`

A string that identifies the animation. Only one animation per unique key is added to the layer. The special key [`kCATransition`](/documentation/QuartzCore/kCATransition) is automatically used for transition animations. You may specify `nil` for this parameter.

## Discussion

If the `duration` property of the animation is zero or negative, the duration is changed to the current value of the [`kCATransactionAnimationDuration`](/documentation/QuartzCore/kCATransactionAnimationDuration) transaction property (if set) or to the default value of `0.25` seconds.

---

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)