• Stars
    star
    23,065
  • Rank 998 (Top 0.02 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight, pure-Swift library for downloading and caching images from the web.

Kingfisher

Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work with remote images in your next app.

Features

  • Asynchronous image downloading and caching.
  • Loading image from either URLSession-based networking or local provided data.
  • Useful image processors and filters provided.
  • Multiple-layer hybrid cache for both memory and disk.
  • Fine control on cache behavior. Customizable expiration date and size limit.
  • Cancelable downloading and auto-reusing previous downloaded content to improve performance.
  • Independent components. Use the downloader, caching system, and image processors separately as you need.
  • Prefetching images and showing them from the cache to boost your app.
  • Extensions for UIImageView, NSImageView, NSButton, UIButton, NSTextAttachment, WKInterfaceImage, TVMonogramView and CPListItem to directly set an image from a URL.
  • Built-in transition animation when setting images.
  • Customizable placeholder and indicator while loading images.
  • Extensible image processing and image format easily.
  • Low Data Mode support.
  • SwiftUI support.

Kingfisher 101

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

import Kingfisher

let url = URL(string: "https://example.com/image.png")
imageView.kf.setImage(with: url)

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

It also works if you use SwiftUI:

var body: some View {
    KFImage(URL(string: "https://example.com/image.png")!)
}

A More Advanced Example

With the powerful options, you can do hard tasks with Kingfisher in a simple way. For example, the code below:

  1. Downloads a high-resolution image.
  2. Downsamples it to match the image view size.
  3. Makes it round cornered with a given radius.
  4. Shows a system indicator and a placeholder image while downloading.
  5. When prepared, it animates the small thumbnail image with a "fade in" effect.
  6. The original large image is also cached to disk for later use, to get rid of downloading it again in a detail view.
  7. A console log is printed when the task finishes, either for success or failure.
let url = URL(string: "https://example.com/high_resolution_image.png")
let processor = DownsamplingImageProcessor(size: imageView.bounds.size)
             |> RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.indicatorType = .activity
imageView.kf.setImage(
    with: url,
    placeholder: UIImage(named: "placeholderImage"),
    options: [
        .processor(processor),
        .scaleFactor(UIScreen.main.scale),
        .transition(.fade(1)),
        .cacheOriginalImage
    ])
{
    result in
    switch result {
    case .success(let value):
        print("Task done for: \(value.source.url?.absoluteString ?? "")")
    case .failure(let error):
        print("Job failed: \(error.localizedDescription)")
    }
}

It is a common situation I can meet in my daily work. Think about how many lines you need to write without Kingfisher!

Method Chaining

If you are not a fan of the kf extension, you can also prefer to use the KF builder and chained the method invocations. The code below is doing the same thing:

// Use `kf` extension
imageView.kf.setImage(
    with: url,
    placeholder: placeholderImage,
    options: [
        .processor(processor),
        .loadDiskFileSynchronously,
        .cacheOriginalImage,
        .transition(.fade(0.25)),
        .lowDataMode(.network(lowResolutionURL))
    ],
    progressBlock: { receivedSize, totalSize in
        // Progress updated
    },
    completionHandler: { result in
        // Done
    }
)

// Use `KF` builder
KF.url(url)
  .placeholder(placeholderImage)
  .setProcessor(processor)
  .loadDiskFileSynchronously()
  .cacheMemoryOnly()
  .fade(duration: 0.25)
  .lowDataModeSource(.network(lowResolutionURL))
  .onProgress { receivedSize, totalSize in  }
  .onSuccess { result in  }
  .onFailure { error in }
  .set(to: imageView)

And even better, if later you want to switch to SwiftUI, just change the KF above to KFImage, and you've done:

struct ContentView: View {
    var body: some View {
        KFImage.url(url)
          .placeholder(placeholderImage)
          .setProcessor(processor)
          .loadDiskFileSynchronously()
          .cacheMemoryOnly()
          .fade(duration: 0.25)
          .lowDataModeSource(.network(lowResolutionURL))
          .onProgress { receivedSize, totalSize in  }
          .onSuccess { result in  }
          .onFailure { error in }
    }
}

Learn More

To learn the use of Kingfisher by more examples, take a look at the well-prepared Cheat Sheet. There we summarized the most common tasks in Kingfisher, you can get a better idea of what this framework can do. There are also some performance tips, remember to check them too.

Requirements

  • iOS 12.0+ / macOS 10.14+ / tvOS 12.0+ / watchOS 5.0+ (if you use only UIKit/AppKit)
  • iOS 14.0+ / macOS 11.0+ / tvOS 14.0+ / watchOS 7.0+ (if you use it in SwiftUI)
  • Swift 5.0+

If you need support from iOS 10 (UIKit/AppKit) or iOS 13 (SwiftUI), use Kingfisher version 6.x. But it won't work with Xcode 13.0 and Xcode 13.1 #1802.

If you need to use Xcode 13.0 and 13.1 but cannot upgrade to v7, use the version6-xcode13 branch. However, you have to drop iOS 10 support due to another Xcode 13 bug.

UIKit SwiftUI Xcode Kingfisher
iOS 10+ iOS 13+ 12 ~> 6.3.1
iOS 11+ iOS 13+ 13 version6-xcode13
iOS 12+ iOS 14+ 13 ~> 7.0

Installation

A detailed guide for installation can be found in Installation Guide.

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/onevcat/Kingfisher.git
  • Select "Up to Next Major" with "7.0.0"

CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!

target 'MyApp' do
  pod 'Kingfisher', '~> 7.0'
end

Carthage

github "onevcat/Kingfisher" ~> 7.0

Migrating

Kingfisher 7.0 Migration - Kingfisher 7.x is NOT fully compatible with the previous version. However, changes should be trivial or not required at all. Please follow the migration guide when you prepare to upgrade Kingfisher in your project.

If you are using an even earlier version, see the guides below to know the steps for migrating.

  • Kingfisher 6.0 Migration - Kingfisher 6.x is NOT fully compatible with the previous version. However, migration is not difficult. Depending on your use cases, it may take no effect or several minutes to modify your existing code for the new version. Please follow the migration guide when you prepare to upgrade Kingfisher in your project.
  • Kingfisher 5.0 Migration - If you are upgrading to Kingfisher 5.x from 4.x, please read this for more information.
  • Kingfisher 4.0 Migration - Kingfisher 3.x should be source compatible to Kingfisher 4. The reason for a major update is that we need to specify the Swift version explicitly for Xcode. All deprecated methods in Kingfisher 3 were removed, so please ensure you have no warning left before you migrate from Kingfisher 3 with Kingfisher 4. If you have any trouble when migrating, please open an issue to discuss.
  • Kingfisher 3.0 Migration - 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 API reference whenever you need more detailed documentation.

Other

Future of Kingfisher

I want to keep Kingfisher lightweight. This framework focuses 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.

Developments and Tests

Any contributing and pull requests are warmly welcome. However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. It would be appreciated if your pull requests could build with all tests green. :)

About the logo

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, open a ticket. Pull requests are warmly welcome as well.

Backers & Sponsors

Open-source projects cannot live long without your help. If you find Kingfisher to be useful, please consider supporting this project by becoming a sponsor. Your user icon or company logo shows up on my blog with a link to your home page.

Become a sponsor through GitHub Sponsors. โค๏ธ

Special thanks to:

imgly

emergetools

License

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

More Repositories

1

VVDocumenter-Xcode

Xcode plug-in which helps you write documentation comment easier, for both Objective-C and Swift.
Objective-C
8,329
star
2

FengNiao

A command line tool for cleaning unused resources in Xcode.
Swift
3,382
star
3

APNGKit

High performance and delightful way to play with APNG format in iOS.
Swift
2,206
star
4

Rainbow

Delightful console output for Swift developers.
Swift
1,839
star
5

Hedwig

Send email to any SMTP server like a boss, in Swift and cross-platform
Swift
1,117
star
6

VVBlurPresentation

A simple way to present a view controller with keeping the blurred previous one.
Objective-C
894
star
7

RandomColorSwift

An attractive color generator for Swift. Ported from randomColor.js.
Swift
628
star
8

XUPorter

Add files and frameworks to your Xcode project after it is generated by Unity 3D.
C#
587
star
9

VVSpringCollectionViewFlowLayout

A spring-like collection view layout. The same effect like iOS7's Message.app
Objective-C
576
star
10

vno-jekyll

Another ported theme for Jekyll
SCSS
544
star
11

vno

Vno, just another ghost theme
CSS
518
star
12

Easy-Cal-Swift

Overload +-*/ operator for Swift, make it easier to use (and not so strict)
Swift
273
star
13

OneV-s-Den

Blog
SCSS
212
star
14

VVImageTint

UIImage category for image tint. For my blog post http://onevcat.com/2013/04/using-blending-in-ios/
Objective-C
193
star
15

UniWebView-Docs

Documentation of UniWebView Project
JavaScript
192
star
16

VCTransitionDemo

A simple demo indicates how to make a custom view controller transition in iOS 7
Objective-C
189
star
17

UserNotificationDemo

Demo project to show how to use UserNotifications framework in iOS 10
Swift
152
star
18

iOSWeekly

iOS Weekly issue for InfoQ CN
133
star
19

ToDoDemo

State-based View Controller demo
Swift
125
star
20

ObservationBP

Proof of concept for back-porting Observation framework to earlier iOS versions
Swift
113
star
21

DebuggableContext

Provides an easy to use action sheet for debugging purpose when shaking your iOS device.
Swift
97
star
22

resume

JavaScript
87
star
23

ComponentNetworking

Swift
83
star
24

swift-ui-book-issue

76
star
25

AddressParser

Email address parser.
Swift
70
star
26

Delegate

A meta library to provide a better `Delegate` pattern.
Swift
67
star
27

SpriteKitSimpleGame

A demo for starting using SpriteKit. Port famous Cocos2DSimpleGame to SpriteKit.
Objective-C
60
star
28

WatchWeather

Swift
47
star
29

MimeType

Get MIME type string from the extension of a file name
Swift
42
star
30

TimerExtensionDemo

A demo to show how to write a today extension.
Swift
41
star
31

ClockFaceView

A demo project for my blog post
Swift
31
star
32

UITestDemo

UITestDemo
Swift
21
star
33

VVStack

Just a TDD demo with XCTest and Kiwi
Objective-C
20
star
34

Noti

Swift
19
star
35

JekyllScroll

JekyllScroll is a theme for Jekyll.
CSS
19
star
36

DispatchMemoryLeakDemo

A demo that reproduce memory leak in iOS 9.2
Swift
19
star
37

VVBorderTimer

An easy border timer with configurable time, corner radius, line width and colors.
Objective-C
17
star
38

Notes

My Notes: http://notes.onevcat.com
17
star
39

lgtm-images

LGTM images collection
Swift
16
star
40

UniWebView-Deprecated

A universal webview plugin for Unity3D. Work with iOS, Android and Mac, using javascript to interact with Unity3D.
Objective-C
14
star
41

UnpauseMe

Script for Unity3D, unpause Unity3D animations or particles when set Time.timeScale = 0.
C#
14
star
42

PhotoData_Kiwi

Use Kiwi to replace objc.io's first issue. Just a demo for Kiwi and my post.
Objective-C
13
star
43

Swift-CI

Swift CI script. Stolen from vapor.
Shell
13
star
44

CounterDemo

A demo app for studying of TCA
Swift
12
star
45

check-lfs

A command-line tool to check binary file committed to a repo.
Swift
11
star
46

Kingfisher-Crash

Crash sample of Kingfisher SwiftUI with SPM on Xcode 11.2 beta
Swift
10
star
47

TexasPoker

A client of Texas Poker
Objective-C
9
star
48

NeuralNetworkLearning

Swift
9
star
49

XcodeScheme

9
star
50

YYTextSample

Sample project for a layout issue in iOS 10
Swift
9
star
51

pokemaster-images

Images for PokeMaster
8
star
52

KeyboardScrollingIssue

Swift
7
star
53

apple-versions

Astro
7
star
54

VVPluginDemo

A demo for how to make a simple Xcode 4 plug-in.
Objective-C
7
star
55

LineSDK-Integration

Integration Test Cases for LINE SDK Swift
Ruby
7
star
56

onevcat

6
star
57

VVPerlBBS

BBS with Perl. Powered by OneV's Den.
Perl
5
star
58

submail-provider

Submail email provider for Vapor
Swift
4
star
59

MwfTableViewController

Extension to UITableViewController in attempt to provide additional features that are reusable in most scenarios.
Objective-C
4
star
60

Flower-Data-Set

Python
4
star
61

GitHubActionPlayground

4
star
62

elm-2048

Practice my elm understanding
Elm
3
star
63

ChatBot

JavaScript
3
star
64

Math.swift

Math
Swift
3
star
65

onevcat.github.com

It's a user page
3
star
66

beginning-elm

JavaScript
3
star
67

LandscapeViewControllerDemo

Just a demo
Objective-C
3
star
68

LearningPerl

It's a repo for Perl learning to get prepared for future working in Kayac.
Objective-C
3
star
69

advent2021

For fun
Swift
2
star
70

qixia.wang

2
star
71

GoogleInteractiveMediaAds-Carthage

2
star
72

LazyContainerBug

State of cells in "lazy" container is lost, if the cell is embedded in a stack
Swift
2
star
73

objc-image-packer

Book build image for ObjCCN
HCL
2
star
74

cool-lang

COOL Lang
Java
2
star
75

JBAlertView

JBAlertView is the new AlertView for showing different alerts type (default, connection, error, ...)
Objective-C
2
star
76

github-battle

Typescript version of GitHub Battle
TypeScript
2
star
77

KF-issue-1931

Swift
1
star
78

VVAlertBanner

A alert banner view which could queue the alert and shou them each by each.
Objective-C
1
star
79

Kingfisher-TestImages

Test images for Swift image downloading framework - Kingfisher.
1
star
80

SPMConfigDemo

Swift
1
star
81

Kingfisher-Review-Sample

Swift
1
star