The library is a platform-agnostic image caching library designed to efficiently store and retrieve images using Core Data. The library supports both iOS and macOS platforms.
- Asynchronous image loading from URLs
- Caching of images to reduce network usage
- Automatic deletion of outdated cache entries
- Platform-agnostic implementation using
UIImage
on iOS andNSImage
on macOS - SwiftUI support with
CAsyncImage()
To integrate asyncImage into your project using Swift Package Manager, add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/baskurthalit/asyncImage.git", .upToNextMajor(from: "1.0.0"))
]
Here's an example of using in SwiftUI.
CAsyncImage(urlString: url) { image in
image
.resizable()
} placeholder: {
ProgressView()
}
Here's an example of extending UIImageView
to load images using ImageLoader
with different approaches:
extension UIImageView {
static let imageLoader: ImageLoader = .init()
func load(from imageUrl: String) {
DispatchQueue.main.async {
Self.imageLoader.loadImage(from: imageUrl) { result in
switch result {
case .success(let image):
self.image = image
case .failure:
break
}
}
}
}
}
extension UIImageView {
static let imageLoader: ImageLoader = .init()
func load(from imageUrl: String) {
Task(priority:.userInitiated) {
image = try? await Self.imageLoader.loadImage(from: imageUrl)
}
}
}
- iOS 13.0 or later
- macOS 11 or later
We appreciate contributions, big or small.
- Clone the project
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -am 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a pull request