Skip to content

nomasystems/image-streamer

Repository files navigation

ImageStreamer

Version iOS 17.0+ macOS 14.0+ tvOS 17.0+ watchOS 10.0+ visionOS 1.0+ Swift 6.0 License MIT

ImageStreamer is a lightweight, high-efficiency image loading library, built entirely with Swift Concurrency (async/await).

Features

  • Task Coalescing: Merges duplicate requests for the same URL automatically.
  • Task Cancellation: Controlled cancel requests when they're no longer needed: checks for task cancellation before making a network request, and before intensive CPU and memory usage.
  • Background Decoding & Downsampling: smooth scrolling and lesser memory usage.
  • Smart Caching: NSCache, light, thread-safe, and gracefully prunes itself —It won't crash your app with an Out-of-Memory (OOM) error
  • Native Async/Await: Clean, readable, and safe code.
  • SwiftUI Ready: Seamless integration via EnvironmentValues.

Supported Formats

ImageStreamer leverages native system decoders. Support depends on whether you are using downsampling (pointSize parameter).

Format Downsampled Full-Size
Raster (JPEG, PNG, HEIC, WebP) ✅ Full Support ✅ Full Support
GIF ⚠️ First frame only ⚠️ First frame only
Vector (SVG, PDF) ❌ Not Supported ⚠️ OS-Dependent

For more technical details, see the Advanced Topics section.

Documentation

Installation

Add ImageStreamer to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/nomasystems/image-streamer.git", from: "1.0.1")
]

Then, add the package product to your target's dependencies:

targets: [
    .target(
        name: "YourApp",
        dependencies: ["ImageStreamer"]
    )
]

Via Xcode

  1. Open your project in Xcode.
  2. Go to File > Add Package Dependencies...
  3. Enter the repository URL: https://github.com/nomasystems/image-streamer.git
  4. Set the Dependency Rule to Up to Next Major Version and enter 1.0.1.
  5. Select the project target where you want to use the library.

Customization and Dependency Injection

The entire ImageStreamer sits behind protocols (ImageStreamerProtocol, ImageFetching), which makes it simple to provide your own caches or mock networks for unit testing.

public init(
    session: ImageFetching = URLSession.shared,
    cache: NSCache<ImageCacheKey, PlatformImage> = NSCache(),
    instrumentation: ImageStreamerInstrumentation? = nil
)

For instance, you might want to create an ImageFetching layer that attaches Auth tokens, applies custom retry logic, or pulls from a local disk cache before hitting URLSession.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

a lightweight, high-efficiency image loading library, built entirely with Swift Concurrency (async/await).

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages