diff --git a/Kingfisher.xcodeproj/project.pbxproj b/Kingfisher.xcodeproj/project.pbxproj index 71d44585d..b3483f934 100644 --- a/Kingfisher.xcodeproj/project.pbxproj +++ b/Kingfisher.xcodeproj/project.pbxproj @@ -1994,7 +1994,6 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2025,7 +2024,6 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2046,7 +2044,6 @@ SDKROOT = appletvos; SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -2067,7 +2064,6 @@ SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -2088,7 +2084,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; - SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -2109,7 +2104,6 @@ SDKROOT = macosx; SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; }; name = Release; }; @@ -2139,7 +2133,6 @@ SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -2172,7 +2165,6 @@ SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -2203,7 +2195,6 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -2234,7 +2225,6 @@ SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -2294,7 +2284,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -2343,7 +2333,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -2371,7 +2361,6 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2399,7 +2388,6 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -2422,7 +2410,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -2439,7 +2426,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Tests/KingfisherTests/KingfisherTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Sources/AnimatedImageView.swift b/Sources/AnimatedImageView.swift index 27c1b362f..340adc3fb 100755 --- a/Sources/AnimatedImageView.swift +++ b/Sources/AnimatedImageView.swift @@ -108,6 +108,7 @@ open class AnimatedImageView: UIImageView { public var needsPrescaling = true /// The animation timer's run loop mode. Default is `NSRunLoopCommonModes`. Set this property to `NSDefaultRunLoopMode` will make the animation pause during UIScrollView scrolling. + #if swift(>=4.2) public var runLoopMode = RunLoop.Mode.common { willSet { if runLoopMode == newValue { @@ -120,6 +121,20 @@ open class AnimatedImageView: UIImageView { } } } + #else + public var runLoopMode = RunLoopMode.commonModes { + willSet { + if runLoopMode == newValue { + return + } else { + stopAnimating() + displayLink.remove(from: .main, forMode: runLoopMode) + displayLink.add(to: .main, forMode: newValue) + startAnimating() + } + } + } + #endif /// The repeat count. public var repeatCount = RepeatCount.infinite { diff --git a/Sources/Image.swift b/Sources/Image.swift index d084f5189..66ae7a6a5 100755 --- a/Sources/Image.swift +++ b/Sources/Image.swift @@ -181,7 +181,11 @@ extension Kingfisher where Base: Image { 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 } @@ -194,7 +198,11 @@ extension Kingfisher where Base: Image { 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 } @@ -431,7 +439,11 @@ extension Kingfisher where Base: Image { } 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 diff --git a/Sources/ImageCache.swift b/Sources/ImageCache.swift index a2fb782ef..74b5dec99 100755 --- a/Sources/ImageCache.swift +++ b/Sources/ImageCache.swift @@ -155,12 +155,23 @@ open class ImageCache { ioQueue.sync { fileManager = FileManager() } #if !os(macOS) && !os(watchOS) + + #if swift(>=4.2) + let memoryNotification = UIApplication.didReceiveMemoryWarningNotification + let terminateNotification = UIApplication.willTerminateNotification + let enterbackgroundNotification = UIApplication.didEnterBackgroundNotification + #else + let memoryNotification = NSNotification.Name.UIApplicationDidReceiveMemoryWarning + let terminateNotification = NSNotification.Name.UIApplicationWillTerminate + let enterbackgroundNotification = NSNotification.Name.UIApplicationDidEnterBackground + #endif + NotificationCenter.default.addObserver( - self, selector: #selector(clearMemoryCache), name: UIApplication.didReceiveMemoryWarningNotification, object: nil) + self, selector: #selector(clearMemoryCache), name: memoryNotification, object: nil) NotificationCenter.default.addObserver( - self, selector: #selector(cleanExpiredDiskCache), name: UIApplication.willTerminateNotification, object: nil) + self, selector: #selector(cleanExpiredDiskCache), name: terminateNotification, object: nil) NotificationCenter.default.addObserver( - self, selector: #selector(backgroundCleanExpiredDiskCache), name: UIApplication.didEnterBackgroundNotification, object: nil) + self, selector: #selector(backgroundCleanExpiredDiskCache), name: enterbackgroundNotification, object: nil) #endif } @@ -540,7 +551,11 @@ 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! diff --git a/Sources/Indicator.swift b/Sources/Indicator.swift index 1f2d7f087..f8fcf09f9 100644 --- a/Sources/Indicator.swift +++ b/Sources/Indicator.swift @@ -135,7 +135,11 @@ final class ActivityIndicator: Indicator { #else let indicatorStyle = UIActivityIndicatorView.Style.gray #endif - activityIndicatorView = UIActivityIndicatorView(style:indicatorStyle) + #if swift(>=4.2) + activityIndicatorView = UIActivityIndicatorView(style: indicatorStyle) + #else + activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: indicatorStyle) + #endif activityIndicatorView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleBottomMargin, .flexibleTopMargin] #endif }