Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

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

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