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

# withAnimation(_:_:)

Returns the result of recomputing the view’s body with the provided
animation.

```
func withAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) 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).

---

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)