Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lorenzofiamingo/swiftui-cached-async-image
CachedAsyncImage is the simplest way to add cache to your AsyncImage.
https://github.com/lorenzofiamingo/swiftui-cached-async-image
Last synced: 3 days ago
JSON representation
CachedAsyncImage is the simplest way to add cache to your AsyncImage.
- Host: GitHub
- URL: https://github.com/lorenzofiamingo/swiftui-cached-async-image
- Owner: lorenzofiamingo
- License: mit
- Created: 2021-10-21T14:34:22.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T07:10:26.000Z (8 months ago)
- Last Synced: 2024-10-30T01:44:21.051Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 35.2 KB
- Stars: 603
- Watchers: 7
- Forks: 62
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-swiftui - lorenzofiamingo/CachedAsyncImage - ποΈ The simplest way to add cache to your AsyncImage. (Samples)
README
# 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:
```swift
AsyncImage(url: logoURL)
```
to this:
```swift
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`:
```swift
CachedAsyncImage(urlRequest: logoURLRequest, urlCache: .imageCache)
``````swift
// URLCache+imageCache.swiftextension 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](https://developer.apple.com/documentation/foundation/nsurlsessiondatadelegate/1411612-urlsession#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 VariadicViews π₯](https://github.com/lorenzofiamingo/swiftui-variadic-views)
[SwiftUI AsyncButton π²οΈ](https://github.com/lorenzofiamingo/swiftui-async-button)
[SwiftUI MapItemPicker πΊοΈ](https://github.com/lorenzofiamingo/swiftui-map-item-picker)
[SwiftUI PhotosPicker π](https://github.com/lorenzofiamingo/swiftui-photos-picker)
[SwiftUI VerticalTabView π](https://github.com/lorenzofiamingo/swiftui-vertical-tab-view)
[SwiftUI SharedObject π±](https://github.com/lorenzofiamingo/swiftui-shared-object)