PitchHut logo
SwiftCache-SDK
A sleek image caching solution for iOS and macOS applications.
Pitch

SwiftCache is a modern, lightweight image caching library built for iOS and macOS. It eliminates dependencies, maintains performance with efficient caching mechanisms, and supports customizable cache lifetimes. Optimized for seamless integration, it adheres to Swift's latest features, making it a future-ready choice for developers.

Description

SwiftCache is a modern and lightweight image caching library designed specifically for iOS and macOS applications. It leverages native Apple APIs, ensuring zero external dependencies while providing exceptional performance and a reduced app size of around 150KB. The library supports a wide range of platforms, including iOS, macOS, tvOS, and watchOS.

Features

  • Zero Dependencies: Built entirely with pure Swift.
  • Lightweight: Optimized for both performance and minimal storage impact.
  • Cross-Platform: Comprehensive support for multiple Apple platforms.
  • TTL Support: Manage cache expiration with customizable time-to-live settings.
  • Three-Tier Caching: Employ a progressive fallback strategy for caching that includes memory, disk, and network layers.
  • Progressive Loading: Display thumbnails while higher resolution images are being loaded.
  • Automatic Downscaling: Efficiently reduce memory usage on both iOS and macOS systems.
  • Lifecycle Awareness: Automatically manages memory based on background and foreground app states.
  • Thread Safety: Utilizes Swift Concurrency to ensure safety across multiple threads.
  • Actor-Based Architecture: Promotes modern Swift practices with no GCD interference.
  • Extensibility: Allows for custom caching strategies and implementations via the Strategy Pattern.
  • Cancellable Requests: Supports canceling downloads when UI elements are reused.
  • LRU Eviction: Automatically cleans up outdated cached images.
  • Analytics: Features built-in performance metrics and cache statistics.
  • Adaptive Cache Policy: Implements on-device tuning for cache limits and TTL based on performance telemetry.
  • Swift 6 Ready: Compatible with the latest Swift concurrency features.

Quick Start

Usage with UIKit

import SwiftCache

// Basic image setting
imageView.sc.setImage(with: url)

// Using placeholder images
imageView.sc.setImage(with: url, placeholder: UIImage(systemName: "photo"))

// Handling completion closure
imageView.sc.setImage(with: url) { result in
    switch result {
    case .success(let image):
        print("Image loaded: \(image.size)")
    case .failure(let error):
        print("Failed: \(error)")
    }
}

// Async/await approach
Task {
    do {
        let image = try await imageView.sc.setImage(with: url)
        print("Image loaded: \(image.size)")
    } catch {
        print("Failed: \(error)")
    }
}

Usage with SwiftUI

import SwiftUI
import SwiftCache

struct ContentView: View {
    var body: some View {
        NavigationStack {
            CachedImage(url: imageURL) {
                ProgressView()
            }
            .frame(width: 300, height: 300)
            .clipShape(RoundedRectangle(cornerRadius: 12))
        }
    }
}

This library offers developers a flexible and powerful solution for handling image caching in their applications, backed by thorough documentation and support for adaptive caching mechanisms that optimize performance based on real usage data. For more detailed information, including configuration options, and performance comparisons with other libraries, refer to the documentation available in the repository.

0 comments

No comments yet.

Sign in to be the first to comment.