A lightweight, customizable Swift Package for asynchronously loading and displaying images with flexible caching options.
- ✅ Asynchronous image loading from URLs
- ✅ State-based content display (loading, success, failure)
- ✅ Flexible caching policies for memory management
- ✅ Cross-platform support (iOS, macOS, watchOS)
- ✅ SwiftUI integration
- ✅ Compatibale with Swift 6
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/engomarelsayed/AsyncImage.git", from: "1.0.0")
]
Or add it directly in Xcode:
- Go to
File
>Add Packages...
- Paste the repository URL:
https://github.com/engomarelsayed/AsyncImage.git
- Click
Add Package
import AsyncImage
import SwiftUI
struct ContentView: View {
var body: some View {
AsyncImage(cachingPolicy: .duringAppSession, from: URL(string: "https://example.com/image.jpg")) { phase in
switch phase {
case .loading:
ProgressView()
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fit)
case .failure:
Image(systemName: "exclamationmark.triangle")
.foregroundColor(.red)
}
}
}
}
AsyncImage offers two caching policies:
// Cache only while the view is active
AsyncImage(cachingPolicy: .withViewCycle, from: imageURL) { ... }
// Cache for the entire app session
AsyncImage(cachingPolicy: .duringAppSession, from: imageURL) { ... }
For detailed API documentation, visit: AsyncImage Documentation
- Swift 5.7+
- iOS 15.0+
- macOS 13.0+
- watchOS 6.0+
- tvOS 14.0+
Contributions are welcome! Please feel free to submit a Pull Request.
AsyncImage is available under the MIT license. See the LICENSE file for more info.