Giter Site home page Giter Site logo

onevcat / kingfisher Goto Github PK

View Code? Open in Web Editor NEW
22.8K 362.0 2.6K 6.26 MB

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

License: MIT License

Swift 94.23% Objective-C 4.42% Ruby 1.36%
swift kingfisher image cache filters image-processor xcode ios macos

kingfisher's Introduction

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.

kingfisher's People

Contributors

arlupin avatar attilathefun avatar chdzq avatar dependabot[bot] avatar dstranz avatar idrougge avatar ignotusverum avatar krider2010 avatar leonerd42 avatar leonpesdk avatar lixiang1994 avatar macecchi avatar makesource avatar nixzhu avatar onevcat avatar pj-lt avatar pnre avatar romanpodymov avatar sunnyyoung avatar tokorom avatar triplecc avatar vfn avatar victorg1991 avatar wangshuaiguo avatar waynehartman avatar xspyhack avatar yeatse avatar yigitcanyurtsever avatar yonaskolb avatar zhongwuzw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kingfisher's Issues

WebP Image Format not cached!

Hi all,

Recently i have started using Webp Image format from google and it really saves a lot of bandwidth. But i'm not able to cache the images. I have tried using using other libraries also but no luck, by far this is the best. I get this error when i try :

: ImageIO: PNG zlib error

It would be great to if anyone could help me out. I use https://github.com/mattt/WebPImageSerialization to display webP images and it works fine.

Kingfisher vs SDWebImage

Good to see the work done to create this purely Swift image framework. I'm using SDWebImage in a lot of my projects, purely because it's known as stable and we're used to it in our projects. As we are now switching to use Swift in our projects, I'm looking for alternatives like Kingfisher.

SDWebImage can be used in iOS 7, what about Kingfisher? This is one important requirement for our projects.
Furthermore, can you tell anything about the performance difference between using SDWebImage and Kingfisher?

某些特殊情况下,jpg格式图片存储后会放大十倍的大小

因为代码中是把下载下来的image通过 UIImagePNGRepresentation(image)转为NSData存储到本地的,某些处理过的PNG会在该方法后,大小会放大十倍,SDWebImage中,在存储图片的时候,会对PNG,JPEG进行判断,是否可以在Kingfisher中加入该判断

WatchKit disable

How to use Kingfisher without WatchKit because i got problem when do compiling ( error: opening import file for module 'WatchKit': Permission denied )

Retina Images in Cache

Hi,
I think there's a problem with retrieving cached images on retina displays. In the diskImageForKey function in the ImageCache extension, the image is retrieved by using

    let image = UIImage(data: data)

So the scale of the device is not considered as it is in the URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) function in ImageDownloader.swift.

I think it should be

    let image = UIImage(data: data, scale: UIScreen.mainScreen().scale)

Maybe it would be nice, if the scaling would be optional, nevertheless I think it should be the same in ImageCache and ImageDownloader.

Keep up with the good work,
matt

_TFFC10Kingfisher10ImageCache41cleanExpiredDiskCacheWithCompletionHanderFS0_FGSqFT_T__T_U_FT_T_

Crashed: com.onevcat.Kingfisher.ImageCache.ioQueue.my_cache
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0xd16e38b6

EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0xd16e38b6

Thread : Crashed: com.onevcat.Kingfisher.ImageCache.ioQueue.my_cache
0 libswiftCore.dylib 0x009c7ab8 swift_getObjCClassMetadata + 199
1 libswiftCore.dylib 0x009b4125 findDynamicValueAndType(swift::OpaqueValue_, swift::Metadata const_, swift::OpaqueValue_&, swift::Metadata const_&) + 80
2 libswiftCore.dylib 0x009b4125 findDynamicValueAndType(swift::OpaqueValue_, swift::Metadata const_, swift::OpaqueValue_&, swift::Metadata const_&) + 80
3 libswiftCore.dylib 0x009b4883 dynamicCastToExistential(swift::OpaqueValue, swift::OpaqueValue_, swift::Metadata const_, swift::ExistentialTypeMetadata const_, swift::DynamicCastFlags) + 30
4 libswiftCore.dylib 0x009b46ad swift_dynamicCast + 484
5 libswiftCore.dylib 0x008a955c TFSs26_forceBridgeFromObjectiveCU__FTPSs9AnyObject_MQ__Q + 208
6 libswiftCore.dylib 0x008da780 TFOSs25_VariantDictionaryStorage8maybeGetUSs8Hashable___fGS_Q_Q0__FQ_GSqQ0_ + 176
7 libswiftCore.dylib 0x008da6c8 TFVSs10Dictionaryg9subscriptFQ_GSqQ0_ + 28
8 Kingfisher 0x00450fc8 TFFC10Kingfisher10ImageCache41cleanExpiredDiskCacheWithCompletionHanderFS0_FGSqFT_T__T_U_FT_T + 2392
9 Kingfisher 0x0044d3f0 TTRXFo__dT__XFdCb__dT_ + 56
10 libdispatch.dylib 0x32da32e3 _dispatch_call_block_and_release + 10
11 libdispatch.dylib 0x32dab729 _dispatch_queue_drain + 1468
12 libdispatch.dylib 0x32da5aad _dispatch_queue_invoke + 84
13 libdispatch.dylib 0x32dacf9f _dispatch_root_queue_drain + 394
14 libdispatch.dylib 0x32dae3c3 _dispatch_worker_thread3 + 94
15 libsystem_pthread.dylib 0x32f0adc1 _pthread_wqthread + 668
16 libsystem_pthread.dylib 0x32f0ab14 start_wqthread + 8

Is there an equivalent to SDWebImageRefreshCached option?

Does Kingfisher have a KingfisherOptionsInfo option (or a plan to add one) that's an equivalent to SDWebImage's SDWebImageRefreshedCached option?

At first glance I thought ForceRefresh was the answer. But looking at your docs, that doesn't seem to be the case. It seems like ForceRefresh always loads the image from the Web while SDWebImage's SDWebImageRefreshedCached instead checks the HTTP caching control headers and honors them, i.e. the image is loaded from the Web when, say, the server doesn't return a 304-Not-Modified, otherwise it's pulled from the cache. The scenario this enables (new image, same url) is pretty common there days; my upcoming app relies on it as well.

Thanks for this library, btw. :) Very timely and much needed since there's really nothing that's pure Swift-based yet.

A question about dispatch_sync

In the initializer of ImageCache:

dispatch_sync(ioQueue, { () -> Void in
    self.fileManager = NSFileManager()
})

Why not use self.fileManager = NSFileManager() directly?

EXC_BAD_INSTRUCTION in cancel disk retrieve task.

The lib dispatch crashes on from Xcode 7 beta 6 on canceling a block. Kingfisher is using dispatch_block_cancel to cancel a local disk retrieving task, so calling cancel on a task will cause a crash in Xcode 7 beta 6.

It seems an Apple's bug with libdispatch. I tried this code in a new iOS project in beta 6, and it leads to the same issue of EXC_BAD_INSTRUCTION:

let block = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS) { () -> Void in
    print("Hello world")
}

dispatch_async(dispatch_get_main_queue(), block)
dispatch_block_cancel(block)

I dug a bit deeper into this, and found it crashes here in queue.c:

void
dispatch_block_cancel(dispatch_block_t db)
{
    dispatch_block_private_data_t dbpd = _dispatch_block_get_data(db);
    if (!dbpd) {
        DISPATCH_CLIENT_CRASH("Invalid block object passed to "
                "dispatch_block_cancel()");
    }

It seems that _dispatch_block_get_data is not returning a valid data chunk.

I opened a radar (rdar://22432170) and decided to wait for a while to see whether it could be solved soon.

Resource Identifier and URL

With the current API we are forced to use the URL as the resource identifier. This won't work in non-trivial scenarios, because we might want the identifier to be different from the URL. For example: creating a thumbnail out of an image.

The image itself as a specific URL (e.g. http://abc.jpg). But I want to cache both http://abc.jpg and http://abc.jpg_thumbnail (this _thumbnail is generated from the original one). The problem is when I want to fetch the thumbnail from the cache. Because if I pass http://abc.jpg_thumbnail and it's not in the cache, it will try to fetch http://abc.jpg_thumbnail which will fail. If I pass http://abc.jpg then it will never touch the thumbnail and get the full size one.

The fundamental problem is: the cache identifier and the resource's URL are coupled. A quick and easy solution would be to use a struct like this:

struct Resource {
let key : String
let resourceURL : NSURL
}

We would then pass this struct, instead of the URL. For example:

public func retrieveImageWithURL(URL: NSURL, optionsInfo: Kingfisher.KingfisherOptionsInfo?, progressBlock: Kingfisher.DownloadProgressBlock?, completionHandler: Kingfisher.CompletionHandler?) -> Kingfisher.RetrieveImageTask

to:

public func retrieveImageWithResource(resource: Resource, optionsInfo: Kingfisher.KingfisherOptionsInfo?, progressBlock: Kingfisher.DownloadProgressBlock?, completionHandler: Kingfisher.CompletionHandler?) -> Kingfisher.RetrieveImageTask

Still, for this kind of cases, we can just leave as is. There is no point on passing a Resource.

public func storeImage(image: UIImage, forKey key: String)

Likewise, when the interaction is with the ImageDownloader it's fine to use a NSURL, since the ImageDownload should be responsible only for interactions with the network.

Without seeing all the code and assuming the code respects the SOLID principles, only the KingfisherManager would have to be updated.

CompletionHandler image not loaded yet.

Hi, I'm trying to use your great api but in order to do so I need the completionHandler to only be called after the image was already set to the UIImageView inside a CollectionView item so that I can resize my cell. How do you recommend me to do so?

Resizing strategy

After downloading an image, I would like to cache a resized version of it (thumbnail). Am I right to assume the best approach for this would be to:

1- Not use the KingfisherManager.swift
2- Create my own Manager that uses ImageCache.swift and ImageDownloader.swift and inject this logic in a method "similar to this".

Bug: Download from https

Hi

I try to download an image:
https://i.scdn.co/image/15b2aeb2ffbe7e279b438d47f6a21d5768f3da9d
This is an image url from spotify api request.

I get this error:
NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813

I know the solution if you use NSURLConnection:

func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace) -> Bool {
return protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust
}

func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge) {
    if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
        let credentials = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust)
        challenge.sender.useCredential(credentials, forAuthenticationChallenge: challenge)
    }
    challenge.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}

Custom request?

Will passing custom requests ever be possible? I want to add an option for basic authentication and it isn't very comfortable to manage this.

Lots of typos in methods

there are a lot of typos e.g. retrive -> retrieve, cahe -> cache and so on...
this should be fixed with highest priority

Can the library support iOS 7.x?

Since iOS 7.x has supported Swift, so why not supporting from iOS 7.x?
Or is it because for recently iOS applications, it is not necessary to support from iOS 7.x?

Thanks for the great job!

Transform an image while drawing

Hi,

I need to apply a series of transformations to an image fetched by Kingfisher. Is there a callback I can use, or a function override, that will let me do something like this?

override func kingfisherWillRenderImage(kfInstance: Kingfisher, view: UIImageView, image: UIImage) -> UIImage {
  let newImage: UIImage = doTransforms(image)
  return newImage
}

Wrong image orientation - Images get rotated after saved to disk

UIImage instances that are created from JPEGs have imageOrientation set accordingly.

When an image is later saved to the disk in JPEG format, the orientation is persisted too in EXIF information. Therefore, when it's loaded later on from disk, it has the correct orientation.

However, Kingfisher is using PNG serialization rather than JPEG that doesn't support the rotation flag (metadata about orientation is not persisted). source: http://stackoverflow.com/a/4868914/1161723

swift2

xcode7-beta2 用模拟器不会有问题,但是在真机就会报下面的错
dyld: Symbol not found: _NSURLSessionTaskPriorityDefault
Referenced from: /private/var/mobile/Containers/Bundle/Application/717BDE02-CDE9-44C8-8E5A-9C927BF03627/xxx.app/Frameworks/Kingfisher.framework/Kingfisher
Expected in: /System/Library/Frameworks/Foundation.framework/Foundation
in /private/var/mobile/Containers/Bundle/Application/717BDE02-CDE9-44C8-8E5A-9C927BF03627/xxx.app/Frameworks/Kingfisher.framework/Kingfisher

我是用pod来导入的
pod 'Kingfisher',:git => 'https://github.com/onevcat/Kingfisher.git',:branch => 'swift-2.0'

Images are swapped in CollectionViewCell

I started using Kingfisher with Swift in CollecitonViewCell and realized some weird behavior.
When ~8 or more cells are shown on screen at a time, same images are shown in multiple cells where no cells are configured with same image url. Also when I scroll, the images are swapped.
Do you see the same behavior ?

Here is my code:

imageView.kf_setImageWithURL(thumbnailUrl,
    placeholderImage: UIImage(named: "loading_image"),
    optionsInfo: nil,
    completionHandler: { [weak imageView] (image, error, cacheType, imageURL) -> () in
        if error == nil {
            imageView?.image = image
        } else {
            imageView?.image = UIImage(named: "no_image")
        }
})

iOS 9, swift 2.0.

Hi, your api is great and works perfect so far for what I've used. However, iOS 9 is just around the corner releasing next week with swift 2.0 and your API is not ready for it. I want to know if you intend to update this API for the new swift and if so how much time do you think it would take. Good luck and success with this great API.

Any detail instruction of how to use the downloader of this library?

First of all,I thank to KingFisher who gave me such fast download and simple image library.

I am now currently developing auction car application.
When i went to each car detail,i will get more than 6 or 10 photos url array which are protected with certificate.And i really don't know how to use this library download manager and image cache.

I also got one problem,too.After i downloaded the images from url,i need to store in some array to show at autolayout scrollview.So,assigning to UIImageView dont work out for me.So i need to know how to use your image downloader and how to pass "https" images url too.I also using SwiftHttp too which include allow all certificate.But i dont know how to embedded with yours.

Here is my old way which show image but taking too long at downloading.And you will see that i append imageFromUrl in image array which will return to scrollview.

Here is the downloading process,i was beginner so my code will be funny to you.:(
http://puu.sh/ibRVg/9e4cf4891b.png
Here is where i show my downloaded images in scrollview.
http://puu.sh/ibRY5/57aa237f06.png

Any help?Please.
Thank you.

Passing in a NSURLSession

I would be great if the ImageDownloader would have a constructor that would receive a NSURLSession as a parameter. This way we could make use of something like DVR for stub images downloads. 👍

Can you add an OnClick callback for your UIImageview extension?

When the image view is clicked, get response from your UIViewcontroller OnClick method which might be the delegate of KF UIImageview.

Make the following way easier by just set an property of event in your kf options.

cell.cellImageView.tag = indexPath.row
cell.cellImageView.userInteractionEnabled = true
var tapGesture = UITapGestureRecognizer(target: self, action: "SomeMethod:")
cell.cellImageView.addGestureRecognizer(tapGesture)

func SomeMethod(recognizer:UIPanGestureRecognizer)
{
    print (recognizer.view?.tag)
}

Server caching directive ignored?

Hi, currently we can only change the maxCachePeriodInSecond inside our app.

It would be more comfortable to change it on the server and send an "Expires"-Header, but Kingfisher seems to ignore this header.

Are there plans to add this feature in the future?

Need a convenient way of fading images

Take an example of how I fade in an image with AlamofireImage:

dishImageView.af_setImageWithURL(URL, imageTransition: .CrossDissolve(0.2))

and the Kingfisher way:

dishImageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil) {
    [weak self] (image, error, cacheType, imageURL) -> () in
    self?.dishImageView.alpha = 0
    UIView.animateWithDuration(0.3) {
        self?.dishImageView.alpha = 1
    }
}

Changing Priority of download-dataTask after it started

Hi,
since I prefetch a lot of images, but want to show a couple of images as fast as possible, I just looked into prioritization of Kingfisher. Looks quite good to me, besides one point: it's not possible to change the priority of a download, once it's started.

As an example: I start to download the images cat[1-100].png and dog[1-100].png. They are all priorized as low since its only prefetching. Now I open the cat view which has a tableView with cat images. So I want to set a couple of images (of the visible cells) via UIImageViews kf_setImageWithURL. Since there are 200 images currently downloading, I need a higher prioritization for the images cat1.png - cat5.png.

But since they are part of the batch download of the prefetching, their url is already in self.fetchLoads in ImageDownloader and hence the started-closure is not called again in line 214 and "task.priority" is not changed to default, although the options dictionary in the downloadImageWithURL-call does not contain the lowPriority option.

A solution could be to attach the downloadTask to the ImageFetchLoad. In this case, it would be also possible to provide auto-priorisation (the more callbacks are attached to the ImageFetchLoad, the higher the priority could be. Some rewrite of ImageDownloader would be needed.

What do you think?

Best regards,
Matt

Do you plan to add animations?

Hi

Do you plan to add some animation if the image downloaded?
use case:
set placeholder image
waiting till the image is downloaded
fade in the downloaded image on the uiimageview

I think it would be great and simple to use somehow

Is it possible to set different cache timers?

I would like to use cache for 2 different kind of images.

  • first is like an avatar, this should be cached for a week or more
  • second is user added content images that should be cached for a day or just a couple of hours.

is that possible?

iOS7

这个库支持iOS7吗?希望可以支持iOS7

when does the image download start?

when i open my app, the avatar image is empty and waits (through async download) for the image.
somehow it takes up to 30 sec until the image is loaded (3kb of size), the reason is not a slow download.
what triggers this download?
is there a timer that will tell KF to wait for n seconds befor its starts to download?

Images stop downloading or stop showing when the internet connection is low

I have to create this issue because i was occurring that issue when my internet connection is low like using from edge speed.Please check my photos sir.
http://puu.sh/ipib2/b770a1f2c9.png ("&w=150" is requesting the image with the size 150x150)
http://puu.sh/ipidl/398e296c6b.png

As you see,there is two car images which are blank.I don't know it stop downloading or not showing because it doesn't give me any error from your library.

If you need to see my API,i can show you.It use protocol to return API results to my car list controller.
"latestCar[]" is the model array that give the cars information when the controller got the results from delegate method.

Xcode´s autocomplete does not work when I include Kingfisher.

Hi,
I installed/added Kingfisher to my project by using 'pod install'.
Then in one of my view controllers I imported Kingfisher.
At first it worked fine but after a short while autocomplete stopped working. And it just stopped working in the files where Kingfisher is imported. I doubt that there is a direct problem with Kingfisher itself but suspect some combination of cocoapods install and Kingfisher so I just wonder if anyone has any idea what might be causing the autocomplete mechanism to stop working.

框架似乎有内存泄露的问题

最近在写一个练手的项目,用了Kingfisher,发现图片加载得越来越多,内存也嗖嗖往上涨,后来换成SDWebImage试了下,好像就没这问题了。我用instrument测试了下,好像确实有点问题,不过我不太会用,只是大概测试了下。不知道需不需要提供什么信息好帮助定位到问题?

iOS7 support?

Does this lib run with iOS7 if I just copy the code?

Crash on startup when using 1.4.0 on iPad with iOS 8.0.2

When updating Kingfisher from 1.3.1 to 1.4.0 (using CocoaPods 0.37.1) our app crashes directly after startup on an iPad 3 with iOS 8.0.2 with following error message:

dyld: Library not loaded: /System/Library/Frameworks/WatchKit.framework/WatchKit
  Referenced from: /private/var/mobile/Containers/Bundle/Application/[udid]/[app-name].app/Frameworks/Kingfisher.framework/Kingfisher
  Reason: image not found

It works on an iPad Air with iOS 8.3 though. It probably tries to load the WKInterfaceImage extension even though it is not referenced in code anywhere. Any idea how to solve this?

Image download not retried, progressBlock and completionHandler not called after an error.

When an error happened (like after a cancelled task) the image download at the same URL will not be retried; the progress and completion callbacks are not executed but just appended to "fetchLoads".

fetchloads

Probably a "cleanForURL" call is missing from the NSURLSessionTaskDelegate:

public func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
    if let URL = task.originalRequest.URL {
        if let error = error { // Error happened
            callbackWithImage(nil, error: error, imageURL: URL)
            cleanForURL(URL) // <---
        } else { //Download finished without error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.