AsyncImage

1.0.3

This pacakge provides a clean way to fetch images from url
EngOmarElsayed/AsyncImage

What's New

1.0.3

2025-04-28T08:23:42Z

Full Changelog: 1.0.2...1.0.3

AsyncImage

A lightweight, customizable Swift Package for asynchronously loading and displaying images with flexible caching options.

Swift iOS macOS watchOS

Features

  • ✅ Asynchronous image loading from URLs
  • ✅ State-based content display (loading, success, failure)
  • ✅ Flexible caching policies for memory management
  • ✅ Cross-platform support (iOS, macOS, watchOS)
  • ✅ SwiftUI integration
  • ✅ Compatibale with Swift 6

Installation

Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/engomarelsayed/AsyncImage.git", from: "1.0.0")
]

Or add it directly in Xcode:

  1. Go to File > Add Packages...
  2. Paste the repository URL: https://github.com/engomarelsayed/AsyncImage.git
  3. Click Add Package

Usage

Basic Usage

import AsyncImage
import SwiftUI

struct ContentView: View {
    var body: some View {
        AsyncImage(cachingPolicy: .duringAppSession, from: URL(string: "https://example.com/image.jpg")) { phase in
            switch phase {
            case .loading:
                ProgressView()
            case .success(let image):
                image
                    .resizable()
                    .aspectRatio(contentMode: .fit)
            case .failure:
                Image(systemName: "exclamationmark.triangle")
                    .foregroundColor(.red)
            }
        }
    }
}

Caching Policies

AsyncImage offers two caching policies:

// Cache only while the view is active
AsyncImage(cachingPolicy: .withViewCycle, from: imageURL) { ... }

// Cache for the entire app session
AsyncImage(cachingPolicy: .duringAppSession, from: imageURL) { ... }

Documentation

For detailed API documentation, visit: AsyncImage Documentation

Requirements

  • Swift 5.7+
  • iOS 15.0+
  • macOS 13.0+
  • watchOS 6.0+
  • tvOS 14.0+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

AsyncImage is available under the MIT license. See the LICENSE file for more info.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue May 13 2025 18:24:19 GMT-0900 (Hawaii-Aleutian Daylight Time)