Explorar el Código

Docs and tests for properties

onevcat hace 10 años
padre
commit
bfa7549ce9

+ 5 - 0
Kingfisher/ImageDownloader.swift

@@ -36,12 +36,17 @@ public typealias ImageDownloaderCompletionHandler = ((image: UIImage?, error: NS
 public struct RetrieveImageDownloadTask {
 public struct RetrieveImageDownloadTask {
     let internalTask: NSURLSessionDataTask
     let internalTask: NSURLSessionDataTask
     
     
+    /// Downloader by which this task is intialized.
     public private(set) weak var ownerDownloader: ImageDownloader?
     public private(set) weak var ownerDownloader: ImageDownloader?
 
 
+    /**
+     Cancel this download task. It will trigger the completion handler with an NSURLErrorCancelled error.
+     */
     public func cancel() {
     public func cancel() {
         ownerDownloader?.cancelDownloadingTask(self)
         ownerDownloader?.cancelDownloadingTask(self)
     }
     }
     
     
+    /// The original request URL of this download task.
     public var URL: NSURL? {
     public var URL: NSURL? {
         return internalTask.originalRequest?.URL
         return internalTask.originalRequest?.URL
     }
     }

+ 3 - 0
Kingfisher/KingfisherManager.swift

@@ -37,7 +37,10 @@ public class RetrieveImageTask {
     // the download task should not begin.
     // the download task should not begin.
     var cancelledBeforeDownlodStarting: Bool = false
     var cancelledBeforeDownlodStarting: Bool = false
     
     
+    /// The disk retrieve task in this image task. Kingfisher will try to look up in cache first. This task represent the cache search task.
     public var diskRetrieveTask: RetrieveImageDiskTask?
     public var diskRetrieveTask: RetrieveImageDiskTask?
+    
+    /// The network retrieve task in this image task.
     public var downloadTask: RetrieveImageDownloadTask?
     public var downloadTask: RetrieveImageDownloadTask?
     
     
     /**
     /**

+ 11 - 0
KingfisherTests/ImageDownloaderTests.swift

@@ -220,6 +220,17 @@ class ImageDownloaderTests: XCTestCase {
         waitForExpectationsWithTimeout(5, handler: nil)
         waitForExpectationsWithTimeout(5, handler: nil)
     }
     }
     
     
+    func testDownloadTaskProperty() {
+        let task = downloader.downloadImageWithURL(NSURL(string: "1234")!, progressBlock: { (receivedSize, totalSize) -> () in
+
+            }) { (image, error, imageURL, originalData) -> () in
+        }
+        
+        XCTAssertNotNil(task, "The task should exist.")
+        XCTAssertEqual(task!.ownerDownloader, downloader, "The owner downloader should be correct")
+        XCTAssertEqual(task!.URL, NSURL(string: "1234"), "The request URL should equal.")
+    }
+    
     func testCancelDownloadTask() {
     func testCancelDownloadTask() {
         
         
         let expectation = expectationWithDescription("wait for downloading")
         let expectation = expectationWithDescription("wait for downloading")