NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 = ) 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!


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

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.