Procházet zdrojové kódy

Remove Swift 4 related code

onevcat před 4 roky
rodič
revize
beeb75c7d9

+ 1 - 1
Demo/Kingfisher-Demo.xcodeproj/project.pbxproj

@@ -519,7 +519,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 1100;
-				LastUpgradeCheck = 1230;
+				LastUpgradeCheck = 1240;
 				ORGANIZATIONNAME = "Wei Wang";
 				TargetAttributes = {
 					4B2944541C3D03880088C3E7 = {

+ 1 - 1
Kingfisher.xcodeproj/project.pbxproj

@@ -723,7 +723,7 @@
 			isa = PBXProject;
 			attributes = {
 				LastSwiftUpdateCheck = 0720;
-				LastUpgradeCheck = 1230;
+				LastUpgradeCheck = 1240;
 				ORGANIZATIONNAME = "Wei Wang";
 				TargetAttributes = {
 					D1ED2D341AD2D09F00CFC3EB = {

+ 1 - 1
Kingfisher.xcodeproj/xcshareddata/xcschemes/Kingfisher.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1230"
+   LastUpgradeVersion = "1240"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 0 - 12
Sources/Cache/ImageCache.swift

@@ -182,19 +182,11 @@ open class ImageCache {
 
         let notifications: [(Notification.Name, Selector)]
         #if !os(macOS) && !os(watchOS)
-        #if swift(>=4.2)
         notifications = [
             (UIApplication.didReceiveMemoryWarningNotification, #selector(clearMemoryCache)),
             (UIApplication.willTerminateNotification, #selector(cleanExpiredDiskCache)),
             (UIApplication.didEnterBackgroundNotification, #selector(backgroundCleanExpiredDiskCache))
         ]
-        #else
-        notifications = [
-            (NSNotification.Name.UIApplicationDidReceiveMemoryWarning, #selector(clearMemoryCache)),
-            (NSNotification.Name.UIApplicationWillTerminate, #selector(cleanExpiredDiskCache)),
-            (NSNotification.Name.UIApplicationDidEnterBackground, #selector(backgroundCleanExpiredDiskCache))
-        ]
-        #endif
         #elseif os(macOS)
         notifications = [
             (NSApplication.willResignActiveNotification, #selector(cleanExpiredDiskCache)),
@@ -708,11 +700,7 @@ open class ImageCache {
 
         func endBackgroundTask(_ task: inout UIBackgroundTaskIdentifier) {
             sharedApplication.endBackgroundTask(task)
-            #if swift(>=4.2)
             task = UIBackgroundTaskIdentifier.invalid
-            #else
-            task = UIBackgroundTaskInvalid
-            #endif
         }
         
         var backgroundTask: UIBackgroundTaskIdentifier!

+ 0 - 8
Sources/Image/Image.swift

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

+ 0 - 4
Sources/Image/ImageDrawing.swift

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

+ 0 - 154
Sources/Utility/Result.swift

@@ -26,160 +26,6 @@
 
 import Foundation
 
-#if swift(>=4.3)
-/// Result type already built-in
-#else
-/// A value that represents either a success or failure, capturing associated
-/// values in both cases.
-public enum Result<Success, Failure> {
-    /// A success, storing a `Value`.
-    case success(Success)
-
-    /// A failure, storing an `Error`.
-    case failure(Failure)
-
-    /// Evaluates the given transform closure when this `Result` instance is
-    /// `.success`, passing the value as a parameter.
-    ///
-    /// Use the `map` method with a closure that returns a non-`Result` value.
-    ///
-    /// - Parameter transform: A closure that takes the successful value of the
-    ///   instance.
-    /// - Returns: A new `Result` instance with the result of the transform, if
-    ///   it was applied.
-    public func map<NewSuccess>(
-        _ transform: (Success) -> NewSuccess
-        ) -> Result<NewSuccess, Failure> {
-        switch self {
-        case let .success(success):
-            return .success(transform(success))
-        case let .failure(failure):
-            return .failure(failure)
-        }
-    }
-
-    /// Evaluates the given transform closure when this `Result` instance is
-    /// `.failure`, passing the error as a parameter.
-    ///
-    /// Use the `mapError` method with a closure that returns a non-`Result`
-    /// value.
-    ///
-    /// - Parameter transform: A closure that takes the failure value of the
-    ///   instance.
-    /// - Returns: A new `Result` instance with the result of the transform, if
-    ///   it was applied.
-    public func mapError<NewFailure>(
-        _ transform: (Failure) -> NewFailure
-        ) -> Result<Success, NewFailure> {
-        switch self {
-        case let .success(success):
-            return .success(success)
-        case let .failure(failure):
-            return .failure(transform(failure))
-        }
-    }
-
-    /// Evaluates the given transform closure when this `Result` instance is
-    /// `.success`, passing the value as a parameter and flattening the result.
-    ///
-    /// - Parameter transform: A closure that takes the successful value of the
-    ///   instance.
-    /// - Returns: A new `Result` instance, either from the transform or from
-    ///   the previous error value.
-    public func flatMap<NewSuccess>(
-        _ transform: (Success) -> Result<NewSuccess, Failure>
-        ) -> Result<NewSuccess, Failure> {
-        switch self {
-        case let .success(success):
-            return transform(success)
-        case let .failure(failure):
-            return .failure(failure)
-        }
-    }
-
-    /// Evaluates the given transform closure when this `Result` instance is
-    /// `.failure`, passing the error as a parameter and flattening the result.
-    ///
-    /// - Parameter transform: A closure that takes the error value of the
-    ///   instance.
-    /// - Returns: A new `Result` instance, either from the transform or from
-    ///   the previous success value.
-    public func flatMapError<NewFailure>(
-        _ transform: (Failure) -> Result<Success, NewFailure>
-        ) -> Result<Success, NewFailure> {
-        switch self {
-        case let .success(success):
-            return .success(success)
-        case let .failure(failure):
-            return transform(failure)
-        }
-    }
-}
-
-extension Result where Failure: Error {
-    /// Returns the success value as a throwing expression.
-    ///
-    /// Use this method to retrieve the value of this result if it represents a
-    /// success, or to catch the value if it represents a failure.
-    ///
-    ///     let integerResult: Result<Int, Error> = .success(5)
-    ///     do {
-    ///         let value = try integerResult.get()
-    ///         print("The value is \(value).")
-    ///     } catch error {
-    ///         print("Error retrieving the value: \(error)")
-    ///     }
-    ///     // Prints "The value is 5."
-    ///
-    /// - Returns: The success value, if the instance represents a success.
-    /// - Throws: The failure value, if the instance represents a failure.
-    public func get() throws -> Success {
-        switch self {
-        case let .success(success):
-            return success
-        case let .failure(failure):
-            throw failure
-        }
-    }
-}
-
-extension Result where Failure == Swift.Error {
-    /// Creates a new result by evaluating a throwing closure, capturing the
-    /// returned value as a success, or any thrown error as a failure.
-    ///
-    /// - Parameter body: A throwing closure to evaluate.
-    @_transparent
-    public init(catching body: () throws -> Success) {
-        do {
-            self = .success(try body())
-        } catch {
-            self = .failure(error)
-        }
-    }
-}
-
-extension Result : Equatable where Success : Equatable, Failure: Equatable { }
-
-extension Result : Hashable where Success : Hashable, Failure : Hashable { }
-
-extension Result : CustomDebugStringConvertible {
-    public var debugDescription: String {
-        var output = "Result."
-        switch self {
-        case let .success(value):
-            output += "success("
-            debugPrint(value, terminator: "", to: &output)
-        case let .failure(error):
-            output += "failure("
-            debugPrint(error, terminator: "", to: &output)
-        }
-        output += ")"
-
-        return output
-    }
-}
-#endif
-
 // These helper methods are not public since we do not want them to be exposed or cause any conflicting.
 // However, they are just wrapper of `ResultUtil` static methods.
 extension Result where Failure: Error {

+ 1 - 12
Sources/Utility/String+MD5.swift

@@ -34,15 +34,9 @@ extension KingfisherWrapper where Base == String {
             return base
         }
 
-        #if swift(>=5.0)
         let message = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) in
             return [UInt8](bytes)
         }
-        #else
-        let message = data.withUnsafeBytes { bytes in
-            return [UInt8](UnsafeBufferPointer(start: bytes, count: data.count))
-        }
-        #endif
 
         let MD5Calculator = MD5(message)
         let MD5Data = MD5Calculator.calculate()
@@ -81,14 +75,9 @@ func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
         }
         return bytes
     }
-
-    #if swift(>=4.1)
+    
     valuePointer.deinitialize(count: 1)
     valuePointer.deallocate()
-    #else
-    valuePointer.deinitialize()
-    valuePointer.deallocate(capacity: 1)
-    #endif
 
     return bytes
 }

+ 0 - 4
Sources/Views/AnimatedImageView.swift

@@ -57,11 +57,7 @@ extension AnimatedImageViewDelegate {
     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.
 /// Different from showing animated image in a normal `UIImageView` (which load all frames at one time),

+ 0 - 4
Sources/Views/Indicator.swift

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

+ 0 - 4
Tests/KingfisherTests/ImageExtensionTests.swift

@@ -42,11 +42,7 @@ class ImageExtensionTests: XCTestCase {
         XCTAssertEqual(format, .GIF)
         
         let raw: [UInt8] = [1, 2, 3, 4, 5, 6, 7, 8]
-        #if swift(>=5.0)
         format = Data(raw).kf.imageFormat
-        #else
-        format = Data(bytes: raw).kf.imageFormat
-        #endif
         XCTAssertEqual(format, .unknown)
     }