From 50a9851d556240fe7341755c3b8ea207b142a803 Mon Sep 17 00:00:00 2001 From: Reda Lemeden Date: Mon, 3 Jul 2017 00:19:42 +0200 Subject: [PATCH] Update to Swift 4 and Xcode 9 --- Demo/Demo.xcodeproj/project.pbxproj | 22 ++++++++++--- Gifu.xcodeproj/project.pbxproj | 32 +++++++++++++++---- .../xcshareddata/xcschemes/Gifu.xcscheme | 4 ++- Source/Classes/AnimatedFrame.swift | 2 +- Source/Classes/Animator.swift | 4 +-- Source/Classes/FrameStore.swift | 8 ++--- Source/Classes/GIFAnimatable.swift | 4 +-- Source/Extensions/Array.swift | 2 +- Source/Helpers/ImageSourceHelpers.swift | 4 +-- Supporting Files/Info.plist | 2 +- 10 files changed, 59 insertions(+), 25 deletions(-) diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index b49d815..fb3fbca 100755 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -122,12 +122,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Kaishin & Co"; TargetAttributes = { 9D98823619BC69CA00B790C6 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Manual; }; }; @@ -187,14 +187,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -233,14 +239,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -273,7 +285,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.kaishin.gifu.demo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Debug; @@ -289,7 +302,8 @@ PRODUCT_BUNDLE_IDENTIFIER = co.kaishin.gifu.demo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 1; }; name = Release; diff --git a/Gifu.xcodeproj/project.pbxproj b/Gifu.xcodeproj/project.pbxproj index 05a1041..2a03f41 100644 --- a/Gifu.xcodeproj/project.pbxproj +++ b/Gifu.xcodeproj/project.pbxproj @@ -220,16 +220,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Kaishin & Co"; TargetAttributes = { 009BD1351BBC7F6500FC982B = { CreatedOnToolsVersion = 7.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 00B8C73D1A364DA400C188E7 = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Manual; }; }; @@ -335,7 +335,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.kaishin.GifuTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -351,7 +352,8 @@ PRODUCT_BUNDLE_IDENTIFIER = co.kaishin.GifuTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -363,14 +365,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -413,14 +421,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -452,6 +466,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -465,7 +480,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -474,6 +490,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -487,7 +504,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Gifu.xcodeproj/xcshareddata/xcschemes/Gifu.xcscheme b/Gifu.xcodeproj/xcshareddata/xcschemes/Gifu.xcscheme index 2424e79..9b6f8d9 100644 --- a/Gifu.xcodeproj/xcshareddata/xcschemes/Gifu.xcscheme +++ b/Gifu.xcodeproj/xcshareddata/xcschemes/Gifu.xcscheme @@ -1,6 +1,6 @@ Void)? = .none) { + func prepareForAnimation(withGIFNamed imageName: String, size: CGSize, contentMode: UIViewContentMode, loopCount: Int = 0, completionHandler: (() -> Void)? = nil) { guard let extensionRemoved = imageName.components(separatedBy: ".")[safe: 0], let imagePath = Bundle.main.url(forResource: extensionRemoved, withExtension: "gif"), let data = try? Data(contentsOf: imagePath) else { return } @@ -83,7 +83,7 @@ public class Animator { /// - parameter contentMode: The view content mode to use for the individual frames. /// - parameter loopCount: Desired number of loops, <= 0 for infinite loop. /// - parameter completionHandler: Completion callback function - func prepareForAnimation(withGIFData imageData: Data, size: CGSize, contentMode: UIViewContentMode, loopCount: Int = 0, completionHandler: ((Void) -> Void)? = .none) { + func prepareForAnimation(withGIFData imageData: Data, size: CGSize, contentMode: UIViewContentMode, loopCount: Int = 0, completionHandler: (() -> Void)? = nil) { frameStore = FrameStore(data: imageData, size: size, contentMode: contentMode, framePreloadCount: frameBufferCount, loopCount: loopCount) frameStore?.shouldResizeFrames = shouldResizeFrames frameStore?.prepareFrames(completionHandler) diff --git a/Source/Classes/FrameStore.swift b/Source/Classes/FrameStore.swift index 274110f..929b06d 100644 --- a/Source/Classes/FrameStore.swift +++ b/Source/Classes/FrameStore.swift @@ -93,7 +93,7 @@ class FrameStore { // MARK: - Frames /// Loads the frames from an image source, resizes them, then caches them in `animatedFrames`. - func prepareFrames(_ completionHandler: ((Void) -> Void)? = .none) { + func prepareFrames(_ completionHandler: (() -> Void)? = nil) { frameCount = Int(CGImageSourceGetCount(imageSource)) animatedFrames.reserveCapacity(frameCount) preloadFrameQueue.async { @@ -115,7 +115,7 @@ class FrameStore { /// - parameter index: The index of the duration. /// - returns: The duration of the given frame. func duration(at index: Int) -> TimeInterval { - return animatedFrames[safe: index]?.duration ?? TimeInterval.infinity + return animatedFrames[safe: index]?.duration ?? TimeInterval.infinity } /// Checks whether the frame should be changed and calls a handler with the results. @@ -146,7 +146,7 @@ private extension FrameStore { /// - parameter index: The index of the frame to load. /// - returns: An optional `UIImage` instance. func loadFrame(at index: Int) -> UIImage? { - guard let imageRef = CGImageSourceCreateImageAtIndex(imageSource, index, nil) else { return .none } + guard let imageRef = CGImageSourceCreateImageAtIndex(imageSource, index, nil) else { return nil } let image = UIImage(cgImage: imageRef) let scaledImage: UIImage? @@ -243,7 +243,7 @@ private extension FrameStore { (0.. bufferFrameCount { return } animatedFrames[index] = animatedFrames[index].makeAnimatedFrame(with: loadFrame(at: index)) diff --git a/Source/Classes/GIFAnimatable.swift b/Source/Classes/GIFAnimatable.swift index ecc7a67..afc2613 100644 --- a/Source/Classes/GIFAnimatable.swift +++ b/Source/Classes/GIFAnimatable.swift @@ -69,7 +69,7 @@ extension GIFAnimatable { /// /// - parameter imageName: The file name of the GIF in the main bundle. /// - parameter loopCount: Desired number of loops, <= 0 for infinite loop. - public func prepareForAnimation(withGIFNamed imageName: String, loopCount: Int = 0, completionHandler: ((Void) -> Void)? = .none) { + public func prepareForAnimation(withGIFNamed imageName: String, loopCount: Int = 0, completionHandler: (() -> Void)? = nil) { animator?.prepareForAnimation(withGIFNamed: imageName, size: frame.size, contentMode: contentMode, loopCount: loopCount, completionHandler: completionHandler) } @@ -77,7 +77,7 @@ extension GIFAnimatable { /// /// - parameter imageData: GIF image data. /// - parameter loopCount: Desired number of loops, <= 0 for infinite loop. - public func prepareForAnimation(withGIFData imageData: Data, loopCount: Int = 0, completionHandler: ((Void) -> Void)? = .none) { + public func prepareForAnimation(withGIFData imageData: Data, loopCount: Int = 0, completionHandler: (() -> Void)? = nil) { if var imageContainer = self as? ImageContainer { imageContainer.image = UIImage(data: imageData) } diff --git a/Source/Extensions/Array.swift b/Source/Extensions/Array.swift index 079a3f6..e643e09 100644 --- a/Source/Extensions/Array.swift +++ b/Source/Extensions/Array.swift @@ -1,5 +1,5 @@ extension Array { subscript(safe index: Int) -> Element? { - return indices ~= index ? self[index] : .none + return indices ~= index ? self[index] : nil } } diff --git a/Source/Helpers/ImageSourceHelpers.swift b/Source/Helpers/ImageSourceHelpers.swift index 75dea8f..0e8889f 100755 --- a/Source/Helpers/ImageSourceHelpers.swift +++ b/Source/Helpers/ImageSourceHelpers.swift @@ -23,7 +23,7 @@ func CGImageFrameDuration(with imageSource: CGImageSource, atIndex index: Int) - /// /// - returns: A capped frame duration. func capDuration(with duration: Double) -> Double? { - if duration < 0 { return .none } + if duration < 0 { return nil } let threshold = 0.02 - Double.ulpOfOne let cappedDuration = duration < threshold ? 0.1 : duration return cappedDuration @@ -35,7 +35,7 @@ func capDuration(with duration: Double) -> Double? { func frameDuration(with properties: GIFProperties) -> Double? { guard let unclampedDelayTime = properties[String(kCGImagePropertyGIFUnclampedDelayTime)], let delayTime = properties[String(kCGImagePropertyGIFDelayTime)] - else { return .none } + else { return nil } return duration(withUnclampedTime: unclampedDelayTime, andClampedTime: delayTime) } diff --git a/Supporting Files/Info.plist b/Supporting Files/Info.plist index db16e4b..f83980e 100644 --- a/Supporting Files/Info.plist +++ b/Supporting Files/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 126 + 128 NSPrincipalClass