Custom Session Async URL Image
A modifier that adds a URL session for asynchronous images contained in the view to use when fetching image data.
Platform Compatibility
iOS 27.0+ iPadOS 27.0+ macOS 27.0+ watchOS 27.0+ tvOS 27.0+ visionOS 27.0+
Tags
SwiftUI Code
let imageURL = URL(string: "https://exploreswiftui.com/images/cats.jpg")!
let imageSession: URLSession = {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = [
"X-Custom-Header": "CustomValue"
]
return URLSession(configuration: configuration)
}()
var body: some View {
AsyncImage(request: URLRequest(url: imageURL)) { image in
image
} placeholder: {
ProgressView()
}
.asyncImageURLSession(imageSession)
}Found an issue or have a suggestion?
Created: June 9, 2026Updated: June 9, 2026