<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSAnimationContext/animate(_:changes:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:So18NSAnimationContextC7SwiftUIE7animate_7changes10completionyAC9AnimationV_yyXEyycSgtFZ"
  },
  "title" : "animate(_:changes:completion:)"
}
-->

# animate(_:changes:completion:)

Animate changes to one or more views using the specified SwiftUI
animation.

```
static func animate(_ animation: Animation, changes: () -> Void, completion: (() -> Void)? = nil)
```

## Parameters

`animation`

The animation to use for the changes.

`changes`

A closure containing the changes to animate.

`completion`

A closure to execute after the animation completes.

## Discussion

Animations performed using this method can be smoothly retargeted while
preserving velocity, just like animations in SwiftUI views.

```
// Grow the window with a smooth spring animation
NSAnimationContext.animate(.smooth) {
    let scaledFrame = myWindowContentView.frame.applying(
        CGAffineTransform(scaleX: 1.5, y: 1.5))
    myWindowContentView.setFrameSize(scaledFrame.size)
}
```

> Note: When a SwiftUI animation is used for animating AppKit’s
> `NSAnimatablePropertyContainer`s, the animations are run in-process,
> and are not backed by `CAAnimation`s in the render server.

---

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)