Enumeration 列挙

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 参照

Asynchronously Loaded Images