Skip to content

Commit

Permalink
Add Swift 4.0 compatibility back
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Nov 3, 2018
1 parent bf63fa8 commit 8b91f9e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
18 changes: 2 additions & 16 deletions Kingfisher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
};
Expand Down Expand Up @@ -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 = "";
};
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 = "";
};
Expand Down Expand Up @@ -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 = "";
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
15 changes: 15 additions & 0 deletions Sources/AnimatedImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions Sources/ImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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!
Expand Down
6 changes: 5 additions & 1 deletion Sources/Indicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8b91f9e

Please sign in to comment.