AsyncImage
struct · iOS 15.0+ · SDK 27.1
nonisolated struct AsyncImage<Content> where Content : ViewA view that asynchronously loads and displays an image. This view uses the shared <doc://com.apple.documentation/documentation/Foundation/URLSession> instance to load an image from a URL that you specify, and then display it. For example, you can display an icon that's stored on a server: AsyncImage(url: URL(string: "https://example.com/icon.png")) .frame(width: 200, height: 200) Until the image loads, the view displays a standard placeholder that fills the available space. After the load completes successfully, the view updates to display the image. In the example above, the icon is smaller than the frame, and so appears smaller than the placeholder.  > Important: You can't apply image-specific modifiers, like ``Image/resizable(capInsets:resizingMode:)``, directly to an `AsyncImage`. Instead, apply them to the ``Image`` instance that your `content` closure gets when defining the view's appearance. You can manipulate the loaded image in the `content` parameter using ``init(url:scale:content:placeholder:)``. For example, you can add a modifier to make the loaded image resizable: AsyncImage(url: URL(string: "https://example.com/icon.png")) { image in image.resizable() } placeholder: { ProgressView() } .frame(width: 50, height: 50) With this initializer, you can also specify a custom placeholder. In the code in the previous example, SwiftUI shows a ``ProgressView`` first, and then the image scaled to fit in the specified frame:  If you use an ``Image`` as a placeholder view and it doesn't load, SwiftUI doesn't show anything as a placeholder and doesn't report an error. To gain more control over the loading process, use the ``init(url:scale:transaction:content:)`` initializer, which takes a `content` closure that receives an ``AsyncImagePhase`` to indicate the state of the loading operation. Return a view that's appropriate for the current phase: 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. } } In iOS 27, macOS 27, watchOS 27, tvOS 27, and visionOS 27 and later, `AsyncImage` caches downloaded image data following the transport protocol. The system creates the cache with a default <doc://com.apple.documentation/documentation/foundation/urlsessionconfiguration>. To change the cache policy, specify the change in <doc://com.apple.documentation/documentation/foundation/urlrequest>, and pass it to ``init(request:scale:transaction:content:)``. To customize the download process in a specific view hierarchy, use ``View/asyncImageURLSession(_:)`` to specify a <doc://com.apple.documentation/documentation/foundation/urlsession>. `AsyncImage` uses this session to perform data tasks when downloading the image data.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
5 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
AsyncImage.init(url:scale:content:placeholder:)
callback cannot propagate synchronous failure
AsyncImage.init(url:scale:transaction:content:)
callback cannot propagate synchronous failure
AsyncImage.init(request:scale:content:placeholder:)
callback cannot propagate synchronous failure
AsyncImage.init(request:scale:transaction:content:)
callback cannot propagate synchronous failure
AsyncImage.body
This protocol needs associated types that cannot yet cross the bridge.