Configs2026年5月17日·1 分钟阅读

Kingfisher — Pure Swift Image Downloading and Caching

A lightweight pure-Swift library for downloading and caching images from the web, with built-in support for UIKit, AppKit, SwiftUI, and image processing.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Kingfisher Overview
通用 CLI 安装命令
npx tokrepo install e7e1fe25-520b-11f1-9bc6-00163e2b0d79

Introduction

Kingfisher is a pure-Swift library for downloading and caching images from the web. It provides a clean API with view extensions for UIKit and SwiftUI, handling the complexity of async downloading, memory and disk caching, and image processing in a type-safe Swift-native way.

What Kingfisher Does

  • Downloads images asynchronously with configurable request modifiers
  • Implements multi-layer caching with memory (NSCache) and disk storage
  • Processes images on download with built-in and custom processors
  • Provides prefetching for collection views to preload upcoming images
  • Supports animated image formats including GIF and APNG

Architecture Overview

Kingfisher centers around KingfisherManager which orchestrates ImageDownloader and ImageCache. Downloads go through a session-based pipeline with request modifiers and retry strategies. Retrieved data passes through ImageProcessor instances before caching. The cache layer is keyed by URL with optional custom keys, and supports configurable memory limits and disk expiration policies.

Self-Hosting & Configuration

  • Install via Swift Package Manager: add the Kingfisher repository URL
  • Configure cache limits with ImageCache.default.memoryStorage.config.totalCostLimit
  • Set disk cache expiration via ImageCache.default.diskStorage.config.expiration
  • Customize the downloader session configuration for certificate pinning
  • Use ImagePrefetcher with collection view data sources for smooth scrolling

Key Features

  • Written entirely in Swift with full Swift concurrency (async/await) support
  • View extensions for UIImageView, NSImageView, UIButton, and SwiftUI views
  • Built-in processors: resize, round corner, blur, tint, and overlay
  • Retry mechanism with configurable max count and delay strategy
  • Cancellation support that propagates through the download-process-cache pipeline

Comparison with Similar Tools

  • SDWebImage — Objective-C core with Swift wrappers; Kingfisher is pure Swift with modern language features
  • Nuke — performance-optimized with pipeline architecture; Kingfisher offers simpler API surface
  • Alamofire Image — thin extension on Alamofire; less caching sophistication
  • Coil (Android) — Kotlin-native equivalent with coroutine integration on Android

FAQ

Q: Does Kingfisher support async/await? A: Yes, all APIs have async/await alternatives starting from version 7.0.

Q: How do I show a loading indicator? A: Use the .placeholder option with any UIView or SwiftUI view, or enable the built-in activity indicator via .indicatorType.

Q: Can I cache processed images separately? A: Yes, processors automatically generate unique cache keys so original and processed versions are stored independently.

Q: Is Kingfisher compatible with visionOS? A: Yes, version 7.x supports iOS, macOS, tvOS, watchOS, and visionOS.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产