Parcourir la source

Align lifecycle name in KF builder

onevcat il y a 5 ans
Parent
commit
405932a25e

+ 3 - 3
Demo/Demo/Kingfisher-Demo/ViewControllers/NormalLoadingViewController.swift

@@ -60,9 +60,9 @@ extension NormalLoadingViewController {
         KF.url(url)
             .fade(duration: 1)
             .loadDiskFileSynchronously()
-            .progress { (received, total) in print("\(indexPath.row + 1): \(received)/\(total)") }
-            .done { print($0) }
-            .catch { err in print("Error: \(err)") }
+            .onProgress { (received, total) in print("\(indexPath.row + 1): \(received)/\(total)") }
+            .onSuccess { print($0) }
+            .onFailure { err in print("Error: \(err)") }
             .set(to: imageView)
     }
     

+ 2 - 2
Demo/Demo/Kingfisher-Demo/ViewControllers/ProcessorCollectionViewController.swift

@@ -74,8 +74,8 @@ class ProcessorCollectionViewController: UICollectionViewController {
         KF.url(url)
             .setProcessor(currentProcessor)
             .serialize(as: .PNG)
-            .done { print($0) }
-            .catch { print($0) }
+            .onSuccess { print($0) }
+            .onFailure { print($0) }
             .set(to: cell.cellImageView)
 
         return cell

+ 3 - 3
Demo/Demo/Kingfisher-Demo/ViewControllers/ProgressiveJPEGViewController.swift

@@ -57,15 +57,15 @@ class ProgressiveJPEGViewController: UIViewController {
             .loadDiskFileSynchronously()
             .progressiveJPEG(progressive)
             .roundCorner(radius: .point(30))
-            .progress { receivedSize, totalSize in
+            .onProgress { receivedSize, totalSize in
                 print("\(receivedSize)/\(totalSize)")
                 self.progressLabel.text = "\(receivedSize) / \(totalSize)"
             }
-            .done { result in
+            .onSuccess { result in
                 print(result)
                 print("Finished")
             }
-            .catch { error in
+            .onFailure { error in
                 print(error)
                 self.progressLabel.text = error.localizedDescription
             }

+ 10 - 10
Sources/General/KF.swift

@@ -97,23 +97,23 @@ extension KF {
         private var options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions)
 
         private var progressBlock: DownloadProgressBlock?
-        private var doneBlock: ((RetrieveImageResult) -> Void)?
-        private var errorBlock: ((KingfisherError) -> Void)?
+        private var successBlock: ((RetrieveImageResult) -> Void)?
+        private var failureBlock: ((KingfisherError) -> Void)?
 
         init(source: Source) {
             self.source = source
         }
 
         private var resultHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? {
-            if doneBlock == nil && errorBlock == nil {
+            if successBlock == nil && failureBlock == nil {
                 return nil
             }
             return { result in
                 switch result {
                 case .success(let result):
-                    self.doneBlock?(result)
+                    self.successBlock?(result)
                 case .failure(let error):
-                    self.errorBlock?(error)
+                    self.failureBlock?(error)
                 }
             }
         }
@@ -250,7 +250,7 @@ extension KF.Builder {
     /// - Parameter block: Called when the image downloading progress gets updated. If the response does not contain an
     ///                    `expectedContentLength`, this block will not be called.
     /// - Returns: A `KF.Builder` with changes applied.
-    public func progress(_ block: DownloadProgressBlock?) -> Self {
+    public func onProgress(_ block: DownloadProgressBlock?) -> Self {
         self.progressBlock = block
         return self
     }
@@ -258,16 +258,16 @@ extension KF.Builder {
     /// Sets the the done block to current builder.
     /// - Parameter block: Called when the image task successfully completes and the the image set is done.
     /// - Returns: A `KF.Builder` with changes applied.
-    public func done(_ block: ((RetrieveImageResult) -> Void)?) -> Self {
-        self.doneBlock = block
+    public func onSuccess(_ block: ((RetrieveImageResult) -> Void)?) -> Self {
+        self.successBlock = block
         return self
     }
 
     /// Sets the catch block to current builder.
     /// - Parameter block: Called when an error happens during the image task.
     /// - Returns: A `KF.Builder` with changes applied.
-    public func `catch`(_ block: ((KingfisherError) -> Void)?) -> Self {
-        self.errorBlock = block
+    public func onFailure(_ block: ((KingfisherError) -> Void)?) -> Self {
+        self.failureBlock = block
         return self
     }
 }

+ 3 - 3
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -167,18 +167,18 @@ class ImageViewExtensionTests: XCTestCase {
         
         group.enter()
         let task1 = KF.url(url)
-            .catch { _ in group.leave() }
+            .onFailure { _ in group.leave() }
             .set(to: imageView)
         
         group.enter()
         KF.url(url)
-            .done { _ in group.leave() }
+            .onSuccess { _ in group.leave() }
             .set(to: imageView)
         
         group.enter()
         let anotherImageView = KFCrossPlatformImageView()
         KF.url(url)
-            .done { _ in group.leave() }
+            .onSuccess { _ in group.leave() }
             .set(to: anotherImageView)
         
         task1?.cancel()

+ 8 - 8
Tests/KingfisherTests/UIButtonExtensionTests.swift

@@ -68,10 +68,10 @@ class UIButtonExtensionTests: XCTestCase {
         var progressBlockIsCalled = false
 
         KF.url(url)
-            .progress { _, _ in
+            .onProgress { _, _ in
                 progressBlockIsCalled = true
             }
-            .done { result in
+            .onSuccess { result in
                 XCTAssertTrue(progressBlockIsCalled)
 
                 XCTAssertTrue(result.image.renderEqual(to: testImage))
@@ -93,10 +93,10 @@ class UIButtonExtensionTests: XCTestCase {
         
         var progressBlockIsCalled = false
         KF.url(url)
-            .progress { _, _ in
+            .onProgress { _, _ in
                 progressBlockIsCalled = true
             }
-            .done { result in
+            .onSuccess { result in
                 XCTAssertTrue(progressBlockIsCalled)
 
                 XCTAssertTrue(result.image.renderEqual(to: testImage))
@@ -116,7 +116,7 @@ class UIButtonExtensionTests: XCTestCase {
         let stub = delayedStub(url, data: testImageData)
 
         KF.url(url)
-            .catch { error in
+            .onFailure { error in
                 XCTAssertTrue(error.isTaskCancelled)
                 delay(0.1) { exp.fulfill() }
             }
@@ -134,7 +134,7 @@ class UIButtonExtensionTests: XCTestCase {
         let stub = delayedStub(url, data: testImageData)
 
         KF.url(url)
-            .catch { error in
+            .onFailure { error in
                 XCTAssertTrue(error.isTaskCancelled)
                 delay(0.1) { exp.fulfill() }
             }
@@ -171,7 +171,7 @@ class UIButtonExtensionTests: XCTestCase {
 
         KF.url(url)
             .onFailureImage(testImage)
-            .catch { error in
+            .onFailure { error in
                 XCTAssertEqual(testImage, self.button.image(for: state))
                 expectation.fulfill()
             }
@@ -188,7 +188,7 @@ class UIButtonExtensionTests: XCTestCase {
 
         KF.url(url)
             .onFailureImage(testImage)
-            .catch { error in
+            .onFailure { error in
                 XCTAssertEqual(testImage, self.button.backgroundImage(for: state))
                 expectation.fulfill()
             }