Explorar o código

Adjust format and minor refactor

onevcat hai 1 ano
pai
achega
5d2bea8c6d
Modificáronse 1 ficheiros con 13 adicións e 6 borrados
  1. 13 6
      Sources/Extensions/HasImageComponent+Kingfisher.swift

+ 13 - 6
Sources/Extensions/HasImageComponent+Kingfisher.swift

@@ -118,7 +118,13 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
     ) -> DownloadTask?
     ) -> DownloadTask?
     {
     {
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
         let options = KingfisherParsedOptionsInfo(KingfisherManager.shared.defaultOptions + (options ?? .empty))
-        return setImage(with: source, placeholder: placeholder, parsedOptions: options, progressBlock: progressBlock, completionHandler: completionHandler)
+        return setImage(
+            with: source, 
+            placeholder: placeholder,
+            parsedOptions: options,
+            progressBlock: progressBlock,
+            completionHandler: completionHandler
+        )
     }
     }
 
 
     /// Sets an image to the image view with a ``Source``.
     /// Sets an image to the image view with a ``Source``.
@@ -210,7 +216,8 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
             placeholder: placeholder,
             placeholder: placeholder,
             options: options,
             options: options,
             progressBlock: progressBlock,
             progressBlock: progressBlock,
-            completionHandler: completionHandler)
+            completionHandler: completionHandler
+        )
     }
     }
 
 
     /// Sets an image to the image view with a requested ``Resource``.
     /// Sets an image to the image view with a requested ``Resource``.
@@ -281,7 +288,8 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
             placeholder: placeholder,
             placeholder: placeholder,
             options: options,
             options: options,
             progressBlock: progressBlock,
             progressBlock: progressBlock,
-            completionHandler: completionHandler)
+            completionHandler: completionHandler
+        )
     }
     }
 
 
     /// Sets an image to the image view with a ``ImageDataProvider``.
     /// Sets an image to the image view with a ``ImageDataProvider``.
@@ -324,6 +332,7 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
     {
     {
         var mutatingSelf = self
         var mutatingSelf = self
         guard let source = source else {
         guard let source = source else {
+            base.image = placeholder
             mutatingSelf.taskIdentifier = nil
             mutatingSelf.taskIdentifier = nil
             completionHandler?(.failure(KingfisherError.imageSettingError(reason: .emptySource)))
             completionHandler?(.failure(KingfisherError.imageSettingError(reason: .emptySource)))
             return nil
             return nil
@@ -372,14 +381,12 @@ extension KingfisherWrapper where Base: KingfisherHasImageComponent {
                     switch result {
                     switch result {
                     case .success(let value):
                     case .success(let value):
                         self.base.image = value.image
                         self.base.image = value.image
-                        completionHandler?(result)
-
                     case .failure:
                     case .failure:
                         if let image = options.onFailureImage {
                         if let image = options.onFailureImage {
                             self.base.image = image
                             self.base.image = image
                         }
                         }
-                        completionHandler?(result)
                     }
                     }
+                    completionHandler?(result)
                 }
                 }
             }
             }
         )
         )