WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.

Forums > SwiftUI

my code works, but it's getting a warning on the .animation line at the end. It says to use "animation(:value:)" instead. For the life of me, I can't figure out what to set "value:" to in order to make it work without the warning... any ideas?

AsyncImage(url: URL(string: "redacted-url-for-posting".replacingOccurrences(of: " ", with: "%20"))) { image in
} placeholder: {
.frame(width: 150, height: 100)
.clipShape(RoundedRectangle(cornerRadius: 12.5))
.animation(.easeInOut(duration: 0.5))

any ideas or suggestions would be appreciated!


Here's an example of animation() using value. Paste into Playgrounds.

// Example for Paul Lee
// 2022.01.29
// Animation using Value.
import SwiftUI
import PlaygroundSupport
struct AnimationTest: View {
    // Think of animationAmount as a light switch
    // The view has one look when value is 1.0 and a different look when value is 1.5
    @State private var animationAmount = 1.0
    var body: some View {
        Button("Tap Me") {
            // important button function here
                .opacity(1.5 - animationAmount)
            // value tells SwiftUI to render scale and opacity between 1.0 and 1.5
            // SwiftUI determines how many frames to render based on duration
                    .easeInOut(duration: 1)
                        .repeatForever(autoreverses: false),
                    value: animationAmount
        .onAppear {
            // Switch the value to 1.5
            // The view has a different look when the value is 1.5
            animationAmount = 1.5

PlaygroundPage.current.setLiveView(AnimationTest().frame(width: 300, height: 300))

In this example, think of animationAmount as a light switch. When the switch has one value, SwiftUI renders the view one way. When the switch gets a different value, the view is rendered another way. SwiftUI sees these two views as the start and ending point of the animation and will render all the frames in between.

In your code, you need to think what the starting view looks like ( i.e. Placeholder = color.red ) and what the ending view looks like (perhaps the final, fetched image?)

Maybe you have a computed boolean? imageIsLoaded, for example? It's false to start, and is true when the images is fetched and loaded. Consider using this as your "light switch" ? When the value changes, it triggers your animation.

Let us know what worked for you.


Thanks! your description made it more clear for me. I was able to figure out what my "light switch" is, even tho it's not in the AsyncImage code anywhere. I'm basically just shuffling the list with an external setting, so using that setting as my value did the trick! thanks!


Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.