Swiftpack.co - lorenzofiamingo/swiftui-cached-async-image as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by lorenzofiamingo.
lorenzofiamingo/swiftui-cached-async-image 2.1.1
CachedAsyncImage is the simplest way to add cache to your AsyncImage.
⭐️ 160
πŸ•“ 2 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/lorenzofiamingo/swiftui-cached-async-image.git", from: "2.1.1")

SwiftUI CachedAsyncImage πŸ—ƒοΈ

CachedAsyncImage is AsyncImage, but with cache capabilities.

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)

In addition to AsyncImage initializers, you have the possibilities to specify the cache you want to use (by default URLCache.shared is used), and to use URLRequest instead of URL:

CachedAsyncImage(urlRequest: logoURLRequest, urlCache: .imageCache)
// URLCache+imageCache.swift

extension URLCache {
    
    static let imageCache = URLCache(memoryCapacity: 512*1000*1000, diskCapacity: 10*1000*1000*1000)
}

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).

Installation

  1. In Xcode, open your project and navigate to File β†’ Swift Packages β†’ Add Package Dependency...
  2. Paste the repository URL (https://github.com/lorenzofiamingo/swiftui-cached-async-image) and click Next.
  3. Click Finish.

Other projects

SwiftUI AsyncButton πŸ–²οΈ

SwiftUI MapItemPicker πŸ—ΊοΈ

SwiftUI PhotosPicker πŸŒ‡

SwiftUI VerticalTabView πŸ”

SwiftUI SharedObject 🍱

GitHub

link
Stars: 160
Last commit: 2 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

SwiftUI CachedAsyncImage 2.1.1
2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics