<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/withAnimation(_:completionCriteria:_:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13withAnimation_18completionCriteria_0E0xAA0D0VSg_AA0d10CompletionF0VxyKXEyyctKlF"
  },
  "title" : "withAnimation(_:completionCriteria:_:completion:)"
}
-->

# withAnimation(_:completionCriteria:_:completion:)

Returns the result of recomputing the view’s body with the provided
animation, and runs the completion when all animations are complete.

```
func withAnimation<Result>(_ animation: Animation? = .default, completionCriteria: AnimationCompletionCriteria = .logicallyComplete, _ body: () throws -> Result, completion: @escaping () -> Void) rethrows -> Result
```

## Discussion

This function sets the given [`Animation`](/documentation/SwiftUI/Animation) as the [`animation`](/documentation/SwiftUI/Transaction/animation)
property of the thread’s current [`Transaction`](/documentation/SwiftUI/Transaction) as well as calling
`Transaction/addAnimationCompletion` with the specified completion.

The completion callback will always be fired exactly one time. If no
animations are created by the changes in `body`, then the callback will be
called immediately after `body`.

---

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)