Contents

AsyncImagePhase

The current phase of the asynchronous image loading operation.

Declaration

enum AsyncImagePhase

Overview

When you create an AsyncImage instance with the init(url:scale:transaction:content:) initializer, you define the appearance of the view using a content closure. SwiftUI calls the closure with a phase value at different points during the load operation to indicate the current state. Use the phase to decide what to draw. For example, you can draw the loaded image if it exists, a view that indicates an error, or a placeholder:

AsyncImage(url: URL(string: "https://example.com/icon.png")) { phase in
    if let image = phase.image {
        image // Displays the loaded image.
    } else if phase.error != nil {
        Color.red // Indicates an error.
    } else {
        Color.blue // Acts as a placeholder.
    }
}

Topics

Getting load phases

Getting the image

Getting the error

See Also

Loading images asynchronously