onevcat 7 лет назад
Родитель
Сommit
4df701e925

+ 6 - 6
Gemfile.lock

@@ -49,7 +49,7 @@ GEM
     colored2 (3.1.2)
     colored2 (3.1.2)
     commander-fastlane (4.4.6)
     commander-fastlane (4.4.6)
       highline (~> 1.7.2)
       highline (~> 1.7.2)
-    concurrent-ruby (1.0.5)
+    concurrent-ruby (1.1.3)
     declarative (0.0.10)
     declarative (0.0.10)
     declarative-option (0.1.0)
     declarative-option (0.1.0)
     domain_name (0.5.20180417)
     domain_name (0.5.20180417)
@@ -58,7 +58,7 @@ GEM
     emoji_regex (0.1.1)
     emoji_regex (0.1.1)
     escape (0.0.4)
     escape (0.0.4)
     excon (0.62.0)
     excon (0.62.0)
-    faraday (0.15.3)
+    faraday (0.15.4)
       multipart-post (>= 1.2, < 3)
       multipart-post (>= 1.2, < 3)
     faraday-cookie_jar (0.0.6)
     faraday-cookie_jar (0.0.6)
       faraday (>= 0.7.4)
       faraday (>= 0.7.4)
@@ -66,7 +66,7 @@ GEM
     faraday_middleware (0.12.2)
     faraday_middleware (0.12.2)
       faraday (>= 0.7.4, < 1.0)
       faraday (>= 0.7.4, < 1.0)
     fastimage (2.1.4)
     fastimage (2.1.4)
-    fastlane (2.107.0)
+    fastlane (2.108.0)
       CFPropertyList (>= 2.3, < 4.0.0)
       CFPropertyList (>= 2.3, < 4.0.0)
       addressable (>= 2.3, < 3.0.0)
       addressable (>= 2.3, < 3.0.0)
       babosa (>= 1.0.2, < 2.0.0)
       babosa (>= 1.0.2, < 2.0.0)
@@ -127,7 +127,7 @@ GEM
     httpclient (2.8.3)
     httpclient (2.8.3)
     i18n (0.9.5)
     i18n (0.9.5)
       concurrent-ruby (~> 1.0)
       concurrent-ruby (~> 1.0)
-    jazzy (0.9.3)
+    jazzy (0.9.4)
       cocoapods (~> 1.0)
       cocoapods (~> 1.0)
       mustache (~> 0.99)
       mustache (~> 0.99)
       open4
       open4
@@ -170,7 +170,7 @@ GEM
     rouge (2.0.7)
     rouge (2.0.7)
     ruby-macho (1.3.1)
     ruby-macho (1.3.1)
     rubyzip (1.2.2)
     rubyzip (1.2.2)
-    sass (3.6.0)
+    sass (3.7.2)
       sass-listen (~> 4.0.0)
       sass-listen (~> 4.0.0)
     sass-listen (4.0.0)
     sass-listen (4.0.0)
       rb-fsevent (~> 0.9, >= 0.9.4)
       rb-fsevent (~> 0.9, >= 0.9.4)
@@ -224,4 +224,4 @@ DEPENDENCIES
   jazzy
   jazzy
 
 
 BUNDLED WITH
 BUNDLED WITH
-   1.16.6
+   1.17.1

+ 12 - 0
Sources/Cache/ImageCache.swift

@@ -181,11 +181,19 @@ open class ImageCache {
         ioQueue = DispatchQueue(label: ioQueueName)
         ioQueue = DispatchQueue(label: ioQueueName)
         
         
         #if !os(macOS) && !os(watchOS)
         #if !os(macOS) && !os(watchOS)
+        #if swift(>=4.2)
         let notifications: [(Notification.Name, Selector)] = [
         let notifications: [(Notification.Name, Selector)] = [
             (UIApplication.didReceiveMemoryWarningNotification, #selector(clearMemoryCache)),
             (UIApplication.didReceiveMemoryWarningNotification, #selector(clearMemoryCache)),
             (UIApplication.willTerminateNotification, #selector(cleanExpiredDiskCache)),
             (UIApplication.willTerminateNotification, #selector(cleanExpiredDiskCache)),
             (UIApplication.didEnterBackgroundNotification, #selector(backgroundCleanExpiredDiskCache))
             (UIApplication.didEnterBackgroundNotification, #selector(backgroundCleanExpiredDiskCache))
         ]
         ]
+        #else
+        let notifications: [(Notification.Name, Selector)] = [
+            (NSNotification.Name.UIApplicationDidReceiveMemoryWarning, #selector(clearMemoryCache)),
+            (NSNotification.Name.UIApplicationWillTerminate, #selector(cleanExpiredDiskCache)),
+            (NSNotification.Name.UIApplicationDidEnterBackground, #selector(backgroundCleanExpiredDiskCache))
+        ]
+        #endif
         notifications.forEach {
         notifications.forEach {
             NotificationCenter.default.addObserver(self, selector: $0.1, name: $0.0, object: nil)
             NotificationCenter.default.addObserver(self, selector: $0.1, name: $0.0, object: nil)
         }
         }
@@ -637,7 +645,11 @@ open class ImageCache {
 
 
         func endBackgroundTask(_ task: inout UIBackgroundTaskIdentifier) {
         func endBackgroundTask(_ task: inout UIBackgroundTaskIdentifier) {
             sharedApplication.endBackgroundTask(task)
             sharedApplication.endBackgroundTask(task)
+            #if swift(>=4.2)
             task = UIBackgroundTaskIdentifier.invalid
             task = UIBackgroundTaskIdentifier.invalid
+            #else
+            task = UIBackgroundTaskInvalid
+            #endif
         }
         }
         
         
         var backgroundTask: UIBackgroundTaskIdentifier!
         var backgroundTask: UIBackgroundTaskIdentifier!

+ 8 - 0
Sources/Image/Image.swift

@@ -146,7 +146,11 @@ extension KingfisherWrapper where Base: Image {
             let rep = NSBitmapImageRep(cgImage: cgimage)
             let rep = NSBitmapImageRep(cgImage: cgimage)
             return rep.representation(using: .png, properties: [:])
             return rep.representation(using: .png, properties: [:])
         #else
         #else
+            #if swift(>=4.2)
             return base.pngData()
             return base.pngData()
+            #else
+            return UIImagePNGRepresentation(base)
+            #endif
         #endif
         #endif
     }
     }
     
     
@@ -163,7 +167,11 @@ extension KingfisherWrapper where Base: Image {
             let rep = NSBitmapImageRep(cgImage: cgImage)
             let rep = NSBitmapImageRep(cgImage: cgImage)
             return rep.representation(using:.jpeg, properties: [.compressionFactor: compressionQuality])
             return rep.representation(using:.jpeg, properties: [.compressionFactor: compressionQuality])
         #else
         #else
+            #if swift(>=4.2)
             return base.jpegData(compressionQuality: compressionQuality)
             return base.jpegData(compressionQuality: compressionQuality)
+            #else
+            return UIImageJPEGRepresentation(base, compressionQuality)
+            #endif
         #endif
         #endif
     }
     }
     
     

+ 4 - 0
Sources/Image/ImageDrawing.swift

@@ -130,7 +130,11 @@ extension KingfisherWrapper where Base: Image {
             }
             }
             
             
             let path = NSBezierPath(roundedRect: rect, byRoundingCorners: corners, radius: radius)
             let path = NSBezierPath(roundedRect: rect, byRoundingCorners: corners, radius: radius)
+            #if swift(>=4.2)
             path.windingRule = .evenOdd
             path.windingRule = .evenOdd
+            #else
+            path.windingRule = .evenOddWindingRule
+            #endif
             path.addClip()
             path.addClip()
             base.draw(in: rect)
             base.draw(in: rect)
             #else
             #else

+ 8 - 2
Sources/Views/AnimatedImageView.swift

@@ -55,6 +55,12 @@ extension AnimatedImageViewDelegate {
     public func animatedImageViewDidFinishAnimating(_ imageView: AnimatedImageView) {}
     public func animatedImageViewDidFinishAnimating(_ imageView: AnimatedImageView) {}
 }
 }
 
 
+#if swift(>=4.2)
+let KFRunLoopModeCommon = RunLoop.Mode.common
+#else
+let KFRunLoopModeCommon = RunLoopMode.commonModes
+#endif
+
 /// Represents a subclass of `UIImageView` for displaying animated image.
 /// Represents a subclass of `UIImageView` for displaying animated image.
 /// Different from showing animated image in a normal `UIImageView` (which load all frames at one time),
 /// Different from showing animated image in a normal `UIImageView` (which load all frames at one time),
 /// `AnimatedImageView` only tries to load several frames (defined by `framePreloadCount`) to reduce memory usage.
 /// `AnimatedImageView` only tries to load several frames (defined by `framePreloadCount`) to reduce memory usage.
@@ -113,10 +119,10 @@ open class AnimatedImageView: UIImageView {
     /// If the downloaded image is larger than the image view's size, it will help to reduce some memory use.
     /// If the downloaded image is larger than the image view's size, it will help to reduce some memory use.
     /// Default is `true`.
     /// Default is `true`.
     public var needsPrescaling = true
     public var needsPrescaling = true
-    
+
     /// The animation timer's run loop mode. Default is `RunLoop.Mode.common`.
     /// The animation timer's run loop mode. Default is `RunLoop.Mode.common`.
     /// Set this property to `RunLoop.Mode.default` will make the animation pause during UIScrollView scrolling.
     /// Set this property to `RunLoop.Mode.default` will make the animation pause during UIScrollView scrolling.
-    public var runLoopMode = RunLoop.Mode.common {
+    public var runLoopMode = KFRunLoopModeCommon {
         willSet {
         willSet {
             guard runLoopMode == newValue else { return }
             guard runLoopMode == newValue else { return }
             stopAnimating()
             stopAnimating()

+ 4 - 0
Sources/Views/Indicator.swift

@@ -126,7 +126,11 @@ final class ActivityIndicator: Indicator {
             #else
             #else
                 let indicatorStyle = UIActivityIndicatorView.Style.gray
                 let indicatorStyle = UIActivityIndicatorView.Style.gray
             #endif
             #endif
+            #if swift(>=4.2)
             activityIndicatorView = UIActivityIndicatorView(style: indicatorStyle)
             activityIndicatorView = UIActivityIndicatorView(style: indicatorStyle)
+            #else
+            activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: indicatorStyle)
+            #endif
         #endif
         #endif
     }
     }
 }
 }

+ 16 - 7
fastlane/Fastfile

@@ -4,15 +4,24 @@ fastlane_version "1.37.0"
 default_platform :ios
 default_platform :ios
 
 
 platform :ios do
 platform :ios do
-  before_all do
-
+  desc "Runs all the tests"
+  lane :tests do
+    test(scheme: "Kingfisher", swift_version: "4.2")
+    test(scheme: "Kingfisher-macOS", swift_version: "4.2")
+    test(scheme: "Kingfisher-tvOS", swift_version: "4.2")
+
+    test(scheme: "Kingfisher", swift_version: "4.0")
+    test(scheme: "Kingfisher-macOS", swift_version: "4.0")
+    test(scheme: "Kingfisher-tvOS", swift_version: "4.0")
   end
   end
 
 
-  desc "Runs all the tests"
-  lane :test do
-    scan(scheme: "Kingfisher", clean: true)
-    scan(scheme: "Kingfisher-macOS", clean: true, destination: 'platform=macOS')
-    scan(scheme: "Kingfisher-tvOS", clean: true)
+  lane :test do |options|
+    if options[:scheme].include? "macOS"
+        scan(scheme: options[:scheme], clean: true, xcargs: "SWIFT_VERSION=#{options[:swift_version]}", destination: "platform=macOS")
+    else
+        scan(scheme: options[:scheme], clean: true, xcargs: "SWIFT_VERSION=#{options[:swift_version]}")
+    end
+    
   end
   end
   
   
   desc "Lint"
   desc "Lint"