A smarter, faster AsyncImage for SwiftUI (iOS) with built-in in-memory and disk caching, cancellation, and Swift 6 concurrency.
🌍 Language · English · Español · Português (Brasil) · 日本語 · 简体中文 · 한국어 · Русский
- SwiftUI-friendly API with an observable view model
- Smart phase handling:
empty,loading,success(Image),failure(Error) - In-memory caching protocol with pluggable implementations
- Disk cache for persistence across launches
- Swift Concurrency (
async/await) with cooperative cancellation - MainActor-safe state updates
💬 Join the discussion. Feedback and questions welcome
- iOS 17+
- Swift 6.1+
- Swift Package Manager
- Open your project in Xcode
- Go to File → Add Packages...
- Enter the repository URL:
https://github.com/gentle-giraffe-apps/SmartAsyncImage.git - Choose a version rule (or
mainwhile developing) - Add the SmartAsyncImage product to your app target
dependencies: [
.package(url: "https://github.com/gentle-giraffe-apps/SmartAsyncImage.git", from: "1.0.0")
]Then add "SmartAsyncImage" to the dependencies of your target.
A runnable SwiftUI demo app is included in this repository using a local package reference.
Path:
Demo/SmartAsyncImageDemo/SmartAsyncImageDemo.xcodeproj
- Clone the repository:
git clone https://github.com/gentle-giraffe-apps/SmartAsyncImage.git
- Open the demo project:
Demo/SmartAsyncImageDemo/SmartAsyncImageDemo.xcodeproj - Select an iOS 17+ simulator.
- Build & Run (⌘R).
The project is preconfigured with a local Swift Package reference to SmartAsyncImage and should run without any additional setup.
import SwiftUI
import SmartAsyncImage
struct MinimalRemoteImageView: View {
let imageURL = URL(string: "https://picsum.photos/300")
var body: some View {
// replace: AsyncImage(url: imageURL) { phase in
// ---------------------------------------------
// with:
SmartAsyncImage(url: imageURL) { phase in
// ----------------------------------------------
switch phase {
case .empty, .loading:
ProgressView()
case .success(let image):
image.resizable().scaledToFit()
case .failure:
Image(systemName: "photo")
}
}
.frame(width: 150, height: 150)
}
}This project enforces quality gates via CI and static analysis:
- CI: All commits to
mainmust pass GitHub Actions checks - Static analysis: DeepSource runs on every commit to
main.
The badge indicates the current number of outstanding static analysis issues. - Test coverage: Codecov reports line coverage for the
mainbranch
These checks are intended to keep the design system safe to evolve over time.
flowchart TD
SAI["SmartAsyncImage<br/>(SwiftUI View)"] --> VM["SmartAsyncImage<br/>ViewModel"]
VM --> Phase["SmartAsyncImage<br/>Phase"]
VM --> MemProto["SmartAsyncImageMemory<br/>CacheProtocol"]
MemProto --> Mem["SmartAsyncImage<br/>MemoryCache<br/>(actor)"]
Mem --> Disk["SmartAsyncImage<br/>DiskCache"]
Disk --> Encoder["SmartAsyncImage<br/>Encoder"]
Mem --> URLSession[["URLSession"]]
Portions of drafting and editorial refinement in this repository were accelerated using large language models (including ChatGPT, Claude, and Gemini) under direct human design, validation, and final approval. All technical decisions, code, and architectural conclusions are authored and verified by the repository maintainer.
MIT License Free for personal and commercial use.
Built by Jonathan Ritchey Gentle Giraffe Apps Senior iOS Engineer --- Swift | SwiftUI | Concurrency