$ show onevcat/Kingfisher
Kingfisher is a pure-Swift library for downloading, caching, and processing images in Apple platform applications (iOS, macOS, tvOS, watchOS, visionOS). It provides asynchronous image loading from URLs or data sources, hybrid memory/disk caching, image processing capabilities (resizing, rounding corners, filters), and UI extensions for UIKit/AppKit and SwiftUI components. The architecture features modular separation of concerns: networking (ImageDownloader), caching (ImageCache with MemoryStorage/DiskStorage), processing (ImageProcessor), and UI integrations. Key entry points include UIImageView.kf extensions, KFImage SwiftUI view, and KingfisherManager.shared for programmatic control. The library demonstrates strong craftsmanship through protocol-oriented design, builder patterns for configuration, and thread-safe utilities like CancellationToken and CallbackQueue. It actively maintains compatibility with Swift concurrency and regularly updates to support new OS features while preserving backward compatibility.
The LLM identified 3 files worth highlighting for reuse:
Defines an enum for controlling callback execution context (main queue, custom queue, or immediate). Self-contained with only Foundation dependency, enables safe callback delivery without retain cycles, and can be extracted to any project needing asynchronous callback management.
Implements a thread-safe cancellation token using atomic operations for managing asynchronous task cancellation. Dependency-free (Foundation only), provides safe concurrency primitives applicable to any Swift project requiring cancellation semantics.
Generic delegate class that holds weak references and supports closure-based delegation to prevent retain cycles. Self-contained pattern with no internal dependencies, easily reusable for implementing delegate patterns in other projects while avoiding memory leaks.