CachedAsyncImage

Async image loading with cache for SwiftUI.

Screenshots

Installation

Swift Package Manager

Going to Xcode File > Add Packages... and add the repository by giving the URL https://github.com/bullinnyc/CachedAsyncImage Enjoy!

Usage

import CachedAsyncImage

Create placeholder and customize image

let exampleUrl = "https://example.com/image.jpg"

CachedAsyncImage(
    url: exampleUrl,
    placeholder: {
        // Create any view for placeholder.
        ZStack {
            Color.yellow
            ProgressView()
        }
    },
    image: {
        // Customize image.
        Image(uiImage: $0)
            .resizable()
            .scaledToFill()
    }
)

Set image cache limit (optional)

Note: The default value is 0, e.g. is no countLimit and is no totalCostLimit.

.onAppear {
    TemporaryImageCache.shared.setCacheLimit(
        countLimit: 1000, // 1000 items
        totalCostLimit: 1024 * 1024 * 200 // 200 MB
    )
}

Requirements

License

  • CachedAsyncImage is distributed under the MIT License.

GitHub

View Github