Kingfisher

 收藏    我在用   0 人在用

一个异步下载和缓存图片的库,你可以把它看做 SDWebImage 的纯 Swift 实现和替代

 GitHub     下载     同步

227    7526    810    29 天前

Kingfisher 是一个异步下载和缓存图片的库,你可以把它看做 SDWebImage 的纯 Swift 实现和替代。它可以帮助简单地实现像是用户头像或者 table view 里面的图片的下载和缓存这样的工作,以提高 app 速度和帮助开发者节省时间。因为我现在工作时使用的语言全面转向 Swift,所以希望尽量使用 Swift 的框架,避免 Objective-C 和 Swift 混编,以便维护和后续开发。另一方面,SDWebImage 里有非常多的功能,而其中很多是用不到的,对于我们的项目来说偏重。所以就写了一个纯 Swift 的,轻量级的库,来处理这方面的需求。相比于一些有些年头的项目,Kingfisher 使用了 Cocoa 框架中一些新的类和特性,从 API 的易用性上来说会有优势。

Kingfisher is a lightweight, pure-Swift library for downloading and caching images from the web. This project is heavily inspired by the popular SDWebImage. It provides you a chance to use a pure-Swift alternative in your next app.

Features

  • [x] Asynchronous image downloading and caching.
  • [x] URLSession-based networking. Basic image processors and filters supplied.
  • [x] Multiple-layer cache for both memory and disk.
  • [x] Cancelable downloading and processing tasks to improve performance.
  • [x] Independent components. Use the downloader or caching system separately as you need.
  • [x] Prefetching images and showing them from cache later when necessary.
  • [x] Extensions for UIImageView, NSImage and UIButton to directly set an image from a URL.
  • [x] Built-in transition animation when setting images.
  • [x] Extensible image processing and image format support.

The simplest use-case is setting an image to an image view with the UIImageView extension:

let url = URL(string: "url_of_your_image")
imageView.kf.setImage(with: url)

Kingfisher will download the image from url, send it to both the memory cache and the disk cache, and display it in imageView. When you use the same code later, the image will be retrieved from cache and shown immediately.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Swift 3 (Kingfisher 3.x), Swift 2.3 (Kingfisher 2.x)

Main development of Kingfisher will support Swift 3. Only critical bug fixes will be made for Kingfisher 2.x.

Kingfisher 3.0 Migration Guide - If you are upgrading to Kingfisher 3.x from an earlier version, please read this for more information.

Next Steps

We prepared a wiki page. You can find tons of useful things there.

  • Installation Guide - Follow it to integrate Kingfisher into your project.
  • Cheat Sheet- Curious about what Kingfisher could do and how would it look like when used in your project? See this page for useful code snippets. If you are already familiar with Kingfisher, you could also learn new tricks to improve the way you use Kingfisher!
  • API Reference - Lastly, please remember to read the full whenever you may need a more detailed reference.

Other

Future of Kingfisher

I want to keep Kingfisher lightweight. This framework will focus on providing a simple solution for downloading and caching images. This doesn’t mean the framework can’t be improved. Kingfisher is far from perfect, so necessary and useful updates will be made to make it better.

The logo of Kingfisher is inspired by Tangram (七巧板), a dissection puzzle consisting of seven flat shapes from China. I believe she's a kingfisher bird instead of a swift, but someone insists that she is a pigeon. I guess I should give her a name. Hi, guys, do you have any suggestions?

Contact

Follow and contact me on Twitter or Sina Weibo. If you find an issue, just open a ticket. Pull requests are warmly welcome as well.

License

Kingfisher is released under the MIT license. See LICENSE for details.

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册