onevcat před 9 roky
rodič
revize
f8aa4ee572

+ 10 - 10
Kingfisher.xcodeproj/project.pbxproj

@@ -24,10 +24,10 @@
 		4B6313F61D766BEF0078E017 /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6313F31D766BEF0078E017 /* Filter.swift */; };
 		4B98674F1CD1CF42003ADAC7 /* AnimatedImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B98674E1CD1CF42003ADAC7 /* AnimatedImageView.swift */; };
 		4B9867501CD1CF42003ADAC7 /* AnimatedImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B98674E1CD1CF42003ADAC7 /* AnimatedImageView.swift */; };
-		4BB24C3D1D79215A00CD5F9C /* ImageSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */; };
-		4BB24C3E1D79215A00CD5F9C /* ImageSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */; };
-		4BB24C3F1D79215A00CD5F9C /* ImageSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */; };
-		4BB24C401D79215A00CD5F9C /* ImageSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */; };
+		4BB24C3D1D79215A00CD5F9C /* CacheSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */; };
+		4BB24C3E1D79215A00CD5F9C /* CacheSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */; };
+		4BB24C3F1D79215A00CD5F9C /* CacheSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */; };
+		4BB24C401D79215A00CD5F9C /* CacheSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */; };
 		4BCCF33D1D5B02F8003387C2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCCF3361D5B02F8003387C2 /* AppDelegate.swift */; };
 		4BCCF33E1D5B02F8003387C2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4BCCF3371D5B02F8003387C2 /* Assets.xcassets */; };
 		4BCCF33F1D5B02F8003387C2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4BCCF3381D5B02F8003387C2 /* Main.storyboard */; };
@@ -476,7 +476,7 @@
 		4B3E714D1B01FEB200F5AAED /* WatchKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WatchKit.framework; path = System/Library/Frameworks/WatchKit.framework; sourceTree = SDKROOT; };
 		4B6313F31D766BEF0078E017 /* Filter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Filter.swift; path = Sources/Filter.swift; sourceTree = "<group>"; };
 		4B98674E1CD1CF42003ADAC7 /* AnimatedImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AnimatedImageView.swift; path = Sources/AnimatedImageView.swift; sourceTree = "<group>"; };
-		4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageSerializer.swift; path = Sources/ImageSerializer.swift; sourceTree = "<group>"; };
+		4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CacheSerializer.swift; path = Sources/CacheSerializer.swift; sourceTree = "<group>"; };
 		4BCCF3361D5B02F8003387C2 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
 		4BCCF3371D5B02F8003387C2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
 		4BCCF3391D5B02F8003387C2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -875,7 +875,7 @@
 				D10945EC1C526B6C001408EB /* ImageDownloader.swift */,
 				D9638B9F1C7DBA660046523D /* ImagePrefetcher.swift */,
 				4B2B8E491D70128200FC4749 /* ImageProcessor.swift */,
-				4BB24C3C1D79215A00CD5F9C /* ImageSerializer.swift */,
+				4BB24C3C1D79215A00CD5F9C /* CacheSerializer.swift */,
 				4BFBEE7C1D7D0C3600699FD3 /* RequrstModifier.swift */,
 				D10945ED1C526B6C001408EB /* ImageTransition.swift */,
 				D10945F11C526B6C001408EB /* KingfisherManager.swift */,
@@ -2048,7 +2048,7 @@
 				182FFF781CC9ACBA004B728D /* NSButton+Kingfisher.swift in Sources */,
 				D10946201C526C61001408EB /* KingfisherOptionsInfo.swift in Sources */,
 				D10946211C526C61001408EB /* Resource.swift in Sources */,
-				4BB24C3F1D79215A00CD5F9C /* ImageSerializer.swift in Sources */,
+				4BB24C3F1D79215A00CD5F9C /* CacheSerializer.swift in Sources */,
 				D9638BA21C7DBA660046523D /* ImagePrefetcher.swift in Sources */,
 				D10946221C526C61001408EB /* String+MD5.swift in Sources */,
 				D10946231C526C61001408EB /* ThreadHelper.swift in Sources */,
@@ -2128,7 +2128,7 @@
 				D9638BA11C7DBA660046523D /* ImagePrefetcher.swift in Sources */,
 				D10946151C526C0D001408EB /* Resource.swift in Sources */,
 				D10946161C526C0D001408EB /* String+MD5.swift in Sources */,
-				4BB24C3E1D79215A00CD5F9C /* ImageSerializer.swift in Sources */,
+				4BB24C3E1D79215A00CD5F9C /* CacheSerializer.swift in Sources */,
 				D10946171C526C0D001408EB /* ThreadHelper.swift in Sources */,
 				D10946181C526C0D001408EB /* UIButton+Kingfisher.swift in Sources */,
 			);
@@ -2143,7 +2143,7 @@
 				D10946251C526CE8001408EB /* Image.swift in Sources */,
 				D10946261C526CE8001408EB /* ImageCache.swift in Sources */,
 				D9638BA31C7DBA660046523D /* ImagePrefetcher.swift in Sources */,
-				4BB24C401D79215A00CD5F9C /* ImageSerializer.swift in Sources */,
+				4BB24C401D79215A00CD5F9C /* CacheSerializer.swift in Sources */,
 				4BFBEE801D7D0C3600699FD3 /* RequrstModifier.swift in Sources */,
 				D10946271C526CE8001408EB /* ImageDownloader.swift in Sources */,
 				D10946281C526CE8001408EB /* KingfisherManager.swift in Sources */,
@@ -2191,7 +2191,7 @@
 				D9638BA01C7DBA660046523D /* ImagePrefetcher.swift in Sources */,
 				D10945FE1C526B86001408EB /* Resource.swift in Sources */,
 				D10945FF1C526B86001408EB /* String+MD5.swift in Sources */,
-				4BB24C3D1D79215A00CD5F9C /* ImageSerializer.swift in Sources */,
+				4BB24C3D1D79215A00CD5F9C /* CacheSerializer.swift in Sources */,
 				D10946001C526B86001408EB /* ThreadHelper.swift in Sources */,
 				D10946011C526B86001408EB /* UIButton+Kingfisher.swift in Sources */,
 			);

+ 1 - 1
Sources/ImageSerializer.swift → Sources/CacheSerializer.swift

@@ -1,5 +1,5 @@
 //
-//  ImageSerializer.swift
+//  CacheSerializer.swift
 //  Kingfisher
 //
 //  Created by Wei Wang on 2016/09/02.

+ 51 - 1
Sources/Image.swift

@@ -138,7 +138,7 @@ extension Image {
         return self
     }
     
-    static func kf_animatedImage(images: [Image], duration: TimeInterval) -> Image? {
+    static func kf_animated(with images: [Image], forDuration forDurationduration: TimeInterval) -> Image? {
         return nil
     }
 #else
@@ -343,6 +343,16 @@ extension Image {
 // MARK: - Image Transforming
 extension Image {
     // MARK: - Round Corner
+    
+    /// Create a round corner image based on `self`.
+    ///
+    /// - parameter radius: The round corner radius of creating image.
+    /// - parameter size:   The target size of creating image.
+    /// - parameter scale:  The image scale of creating image.
+    ///
+    /// - returns: An image with round corner of `self`.
+    ///
+    /// - Note: This method only works for CG-based image.
     public func kf_image(withRoundRadius radius: CGFloat, fit size: CGSize, scale: CGFloat) -> Image {
         
         guard let cgImage = cgImage else {
@@ -386,6 +396,14 @@ extension Image {
     #endif
     
     // MARK: - Resize
+    
+    /// Resize `self` to an image of new size.
+    ///
+    /// - parameter size: The target size.
+    ///
+    /// - returns: An image with new size.
+    ///
+    /// - Note: This method only works for CG-based image.
     public func kf_resize(to size: CGSize) -> Image {
         
         guard let cgImage = cgImage?.fixed else {
@@ -404,6 +422,14 @@ extension Image {
     }
     
     // MARK: - Blur
+    
+    /// Create an image with blur effect based on `self`.
+    ///
+    /// - parameter radius: The blur radius should be used when creating blue.
+    ///
+    /// - returns: An image with blur effect applied.
+    ///
+    /// - Note: This method only works for CG-based image.
     public func kf_blurred(withRadius radius: CGFloat) -> Image {
         #if os(watchOS)
             return self
@@ -503,6 +529,15 @@ extension Image {
     }
     
     // MARK: - Overlay
+    
+    /// Create an image from `self` with a color overlay layer.
+    ///
+    /// - parameter color:    The color should be use to overlay.
+    /// - parameter fraction: Fraction of input color. From 0.0 to 1.0. 0.0 means solid color, 1.0 means transparent overlay.
+    ///
+    /// - returns: An image with a color overlay applied.
+    ///
+    /// - Note: This method only works for CG-based image.
     public func kf_overlaying(with color: Color, fraction: CGFloat) -> Image {
 
         guard let cgImage = cgImage?.fixed else {
@@ -531,6 +566,12 @@ extension Image {
     }
     
     // MARK: - Tint
+    
+    /// Create an image from `self` with a color tint.
+    ///
+    /// - parameter color: The color should be used to tint `self`
+    ///
+    /// - returns: An image with a color tint applied.
     public func kf_tinted(with color: Color) -> Image {
         #if os(watchOS)
         return self
@@ -540,6 +581,15 @@ extension Image {
     }
     
     // MARK: - Color Control
+    
+    /// Create an image from `self` with color control.
+    ///
+    /// - parameter brightness: Brightness changing to image.
+    /// - parameter contrast:   Contrast changing to image.
+    /// - parameter saturation: Saturation changing to image.
+    /// - parameter inputEV:    InputEV changing to image.
+    ///
+    /// - returns: An image with color control applied.
     public func kf_adjusted(brightness: CGFloat, contrast: CGFloat, saturation: CGFloat, inputEV: CGFloat) -> Image {
         #if os(watchOS)
         return self

+ 14 - 20
Sources/ImageCache.swift

@@ -136,7 +136,7 @@ open class ImageCache {
         NotificationCenter.default.addObserver(
             self, selector: #selector(clearMemoryCache), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
         NotificationCenter.default.addObserver(
-            self, selector: #selector(cleanExpiredDiskCache_), name: .UIApplicationWillTerminate, object: nil)
+            self, selector: #selector(cleanExpiredDiskCache), name: .UIApplicationWillTerminate, object: nil)
         NotificationCenter.default.addObserver(
             self, selector: #selector(backgroundCleanExpiredDiskCache), name: .UIApplicationDidEnterBackground, object: nil)
 #endif
@@ -256,9 +256,10 @@ extension ImageCache {
     
     - returns: The retrieving task.
     */
-    @discardableResult public func retrieveImage(forKey key: String,
-                                                 options: KingfisherOptionsInfo?,
-                                                 completionHandler: ((Image?, CacheType) -> ())?) -> RetrieveImageDiskTask?
+    @discardableResult
+    open func retrieveImage(forKey key: String,
+                               options: KingfisherOptionsInfo?,
+                     completionHandler: ((Image?, CacheType) -> ())?) -> RetrieveImageDiskTask?
     {
         // No completion handler. Not start working and early return.
         guard let completionHandler = completionHandler else {
@@ -363,29 +364,22 @@ extension ImageCache {
     @objc public func clearMemoryCache() {
         memoryCache.removeAllObjects()
     }
-
-    /**
-    Clear disk cache.
-    */
-    private func clearDiskCache_() {
-        clearDiskCache(with: nil)
-    }
     
     /**
     Clear disk cache. This is an async operation.
     
     - parameter completionHander: Called after the operation completes.
     */
-    open func clearDiskCache(with completionHander: (()->())? = nil) {
+    open func clearDiskCache(completion handler: (()->())? = nil) {
         ioQueue.async {
             do {
                 try self.fileManager.removeItem(atPath: self.diskCachePath)
                 try self.fileManager.createDirectory(atPath: self.diskCachePath, withIntermediateDirectories: true, attributes: nil)
             } catch _ { }
             
-            if let completionHander = completionHander {
+            if let handler = handler {
                 DispatchQueue.main.async {
-                    completionHander()
+                    handler()
                 }
             }
         }
@@ -394,8 +388,8 @@ extension ImageCache {
     /**
     Clean expired disk cache. This is an async operation.
     */
-    @objc fileprivate func cleanExpiredDiskCache_() {
-        cleanExpiredDiskCache(with: nil)
+    @objc fileprivate func cleanExpiredDiskCache() {
+        cleanExpiredDiskCache(completion: nil)
     }
     
     /**
@@ -403,7 +397,7 @@ extension ImageCache {
     
     - parameter completionHandler: Called after the operation completes.
     */
-    open func cleanExpiredDiskCache(with completionHandler: (()->())? = nil) {
+    open func cleanExpiredDiskCache(completion handler: (()->())? = nil) {
         
         // Do things in cocurrent io queue
         ioQueue.async {
@@ -458,7 +452,7 @@ extension ImageCache {
                     NotificationCenter.default.post(name: .KingfisherDidCleanDiskCache, object: self, userInfo: [KingfisherDiskCacheCleanedHashKey: cleanedHashes])
                 }
                 
-                completionHandler?()
+                handler?()
             }
         }
     }
@@ -595,11 +589,11 @@ extension ImageCache {
     
     - parameter completionHandler: Called with the calculated size when finishes.
     */
-    open func calculateDiskCacheSize(completionHandler: ((_ size: UInt) -> ())) {
+    open func calculateDiskCacheSize(completion handler: ((_ size: UInt) -> ())) {
         ioQueue.async {
             let (_, diskCacheSize, _) = self.travelCachedFiles(onlyForCacheSize: true)
             DispatchQueue.main.async {
-                completionHandler(diskCacheSize)
+                handler(diskCacheSize)
             }
         }
     }

+ 3 - 20
Sources/ImageDownloader.swift

@@ -258,23 +258,6 @@ open class ImageDownloader: NSObject {
 
 // MARK: - Download method
 extension ImageDownloader {
-    /**
-    Download an image with a URL.
-    
-    - parameter url:               Target URL.
-    - parameter progressBlock:     Called when the download progress updated.
-    - parameter completionHandler: Called when the download progress finishes.
-    
-    - returns: A downloading task. You could call `cancel` on it to stop the downloading process.
-    */
-    @discardableResult
-    open func downloadImage(with url: URL,
-                       progressBlock: ImageDownloaderProgressBlock?,
-                   completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
-    {
-        return downloadImage(with: url, options: nil, progressBlock: progressBlock, completionHandler: completionHandler)
-    }
-    
     /**
     Download an image with a URL and option.
     
@@ -287,9 +270,9 @@ extension ImageDownloader {
     */
     @discardableResult
     open func downloadImage(with url: URL,
-                             options: KingfisherOptionsInfo?,
-                       progressBlock: ImageDownloaderProgressBlock?,
-                   completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
+                             options: KingfisherOptionsInfo? = nil,
+                       progressBlock: ImageDownloaderProgressBlock? = nil,
+                   completionHandler: ImageDownloaderCompletionHandler? = nil) -> RetrieveImageDownloadTask?
     {
         return downloadImage(with: url,
                 retrieveImageTask: nil,

+ 1 - 1
Sources/ImageView+Kingfisher.swift

@@ -66,7 +66,7 @@ extension ImageView {
         
         guard let resource = resource else {
             completionHandler?(nil, nil, .none, nil)
-            return .emptyTask
+            return .empty
         }
         
         let showIndicatorWhenLoading = kf_showIndicatorWhenLoading

+ 1 - 1
Sources/KingfisherManager.swift

@@ -37,7 +37,7 @@ public typealias CompletionHandler = ((_ image: Image?, _ error: NSError?, _ cac
 /// It contains an async task of getting image from disk and from network.
 public class RetrieveImageTask {
     
-    static let emptyTask = RetrieveImageTask()
+    static let empty = RetrieveImageTask()
     
     // If task is canceled before the download task started (which means the `downloadTask` is nil),
     // the download task should not begin.

+ 2 - 2
Sources/NSButton+Kingfisher.swift

@@ -58,7 +58,7 @@ extension NSButton {
         
         guard let resource = resource else {
             completionHandler?(nil, nil, .none, nil)
-            return .emptyTask
+            return .empty
         }
         
         kf_setWebURL(resource.downloadURL)
@@ -144,7 +144,7 @@ extension NSButton {
         
         guard let resource = resource else {
             completionHandler?(nil, nil, .none, nil)
-            return .emptyTask
+            return .empty
         }
         
         kf_setAlternateWebURL(resource.downloadURL)

+ 2 - 2
Sources/UIButton+Kingfisher.swift

@@ -57,7 +57,7 @@ extension UIButton {
         
         guard let resource = resource else {
             completionHandler?(nil, nil, .none, nil)
-            return .emptyTask
+            return .empty
         }
         
         kf_setWebURL(resource.downloadURL, for: state)
@@ -162,7 +162,7 @@ extension UIButton {
         
         guard let resource = resource else {
             completionHandler?(nil, nil, .none, nil)
-            return .emptyTask
+            return .empty
         }
         
         kf_setBackgroundWebURL(resource.downloadURL, for: state)