CachedAsyncImage

0.0.4

CachedAsyncImage is a Swift Package for asynchronously loading images from the web and caching them.
0xWDG/CachedAsyncImage

What's New

0.0.4

2026-06-15T19:08:35Z

Updated platform declarations, dependencies, and files across Package.swift, README.md, and related source/test files to support iOS 15+, macOS 12+, tvOS 15+, and watchOS 8+. Adjusted ContentView and README for clarity.
Full Changelog: 0.0.3...0.0.4

CachedAsyncImage

CachedAsyncImage is a Swift Package for asynchronously loading images from the web and caching them.

Swift Package Manager License

Requirements

  • Swift 5.8+
  • iOS 15+, macOS 12+, tvOS 15+, watchOS 8+

Installation (Package.swift)

dependencies: [
    .package(url: "https://github.com/0xWDG/CachedAsyncImage.git", branch: "main"),
],
targets: [
    .target(name: "MyTarget", dependencies: [
        .product(name: "CachedAsyncImage", package: "CachedAsyncImage"),
    ]),
]

Installation (Xcode)

  1. In Xcode, open your project and navigate to File โ†’ Swift Packages โ†’ Add Package Dependency...
  2. Paste the repository URL (https://github.com/0xWDG/CachedAsyncImage) and click Next.
  3. Click Finish.

Usage

CachedAsyncImage has the exact same API and behavior as AsyncImage, so you just have to change this:

AsyncImage(url: logoURL)

to this:

CachedAsyncImage(url: logoURL)

example:

import SwiftUI
import CachedAsyncImage

struct ContentView: View {
    var body: some View {
        VStack {
            CachedAsyncImage(
                url: URL(
                    string: "https://wesleydegroot.nl/assets/avatar/avatar.webp"
                )
            ) { image in
                image
                    .resizable()
                    .frame(width: 250, height: 250)
            } placeholder: {
                ProgressView()
            }
        }
        .padding()
    }
}

In addition to AsyncImage initializers, you can specify the cache you want to use. By default, URLCache.shared is used:

CachedAsyncImage(url: logoURL, urlCache: .imageCache)
// URLCache+imageCache.swift

extension URLCache {

    static let imageCache = URLCache(memoryCapacity: 512_000_000, diskCapacity: 10_000_000_000)
}

Remember when setting the cache the response (in this case our image) must be no larger than about 5% of the disk cache (See this discussion).

Contact

๐Ÿฆ‹ @0xWDG ๐Ÿ˜ mastodon.social/@0xWDG ๐Ÿฆ @0xWDG ๐Ÿงต @0xWDG ๐ŸŒ wesleydegroot.nl ๐Ÿค– Discord

Interested learning more about Swift? Check out my blog.

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Jun 21 2026 01:38:13 GMT-0900 (Hawaii-Aleutian Daylight Time)