onevcat 10 лет назад
Родитель
Сommit
aa6050f5e4
3 измененных файлов с 26 добавлено и 9 удалено
  1. 6 1
      Kingfisher/ImageDownloader.swift
  2. 2 2
      Kingfisher/KingfisherManager.swift
  3. 18 6
      README.md

+ 6 - 1
Kingfisher/ImageDownloader.swift

@@ -35,11 +35,16 @@ public typealias ImageDownloaderCompletionHandler = ((image: UIImage?, error: NS
 /// Download task.
 public struct RetrieveImageDownloadTask {
     let internalTask: NSURLSessionDataTask
-    weak var ownerDownloader: ImageDownloader?
+    
+    public private(set) weak var ownerDownloader: ImageDownloader?
 
     public func cancel() {
         ownerDownloader?.cancelDownloadingTask(self)
     }
+    
+    public var URL: NSURL? {
+        return internalTask.originalRequest?.URL
+    }
 }
 
 private let defaultDownloaderName = "default"

+ 2 - 2
Kingfisher/KingfisherManager.swift

@@ -37,8 +37,8 @@ public class RetrieveImageTask {
     // the download task should not begin.
     var cancelledBeforeDownlodStarting: Bool = false
     
-    var diskRetrieveTask: RetrieveImageDiskTask?
-    var downloadTask: RetrieveImageDownloadTask?
+    public var diskRetrieveTask: RetrieveImageDiskTask?
+    public var downloadTask: RetrieveImageDownloadTask?
     
     /**
     Cancel current task. If this task does not begin or already done, do nothing.

+ 18 - 6
README.md

@@ -58,7 +58,7 @@ source 'https://github.com/CocoaPods/Specs.git'
 platform :ios, '8.0'
 use_frameworks!
 
-pod 'Kingfisher', '~> 1.8'
+pod 'Kingfisher', '~> 1.9'
 ```
 
 Then, run the following command:
@@ -83,7 +83,7 @@ $ brew install carthage
 To integrate Kingfisher into your Xcode project using Carthage, specify it in your `Cartfile`:
 
 ``` ogdl
-github "onevcat/Kingfisher" ~> 1.8
+github "onevcat/Kingfisher" ~> 1.9
 ```
 
 Then, run the following command to build the Kingfisher framework:
@@ -215,16 +215,28 @@ imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!,
 
 #### Cancel Task
 
-All `kf_setImageWithURL` methods return a `RetrieveImageTask` object. You can `cancel` the task if the images are not needed.
+You can `cancel` the task if the images are not needed anymore. 
+It could be useful when you use Kingfisher to set an image in a cell of table view or collection view, 
+but users scroll the view and the cells disappeared before downloading finishing.
 
 ``` swift
-let task = imageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!)
-task.cancel()
+imageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!)
 
 // The image retrieving will stop.
+imageView.kf_cancelDownloadTask()
 ```
 
-There is a category for `UIButton` as well.
+All `kf_setImageWithURL` methods return a `RetrieveImageTask` object as well. You can also hold and manage it if you need to apply some check:
+
+``` swift
+let task = imageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!)
+
+let urlShouldNotBeCancelled: URL = ...
+
+if task.downloadTask?.URL != urlShouldNotBeCancelled {
+    task.cancel()
+}
+```
 
 ### Downloader & Cache system