Skip to content

Commit

Permalink
Swift 4.2 migration (#196)
Browse files Browse the repository at this point in the history
* Swift 4.2

* update travis to match current swift version
  • Loading branch information
mezhevikin authored and RuiAAPeres committed Nov 13, 2018
1 parent a4de06a commit ffe41df
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
osx_image: xcode9
osx_image: xcode10
language: objective-c

script:
Expand Down
2 changes: 1 addition & 1 deletion Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

return true
}
Expand Down
2 changes: 1 addition & 1 deletion Example/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CounterView: UIView {
let stringTemplate = "%d of %d"
let countString = String(format: stringTemplate, arguments: [currentIndex + 1, count])

countLabel.attributedText = NSAttributedString(string: countString, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 17), NSAttributedStringKey.foregroundColor: UIColor.white])
countLabel.attributedText = NSAttributedString(string: countString, attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 17), NSAttributedString.Key.foregroundColor: UIColor.white])
}

override func layoutSubviews() {
Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ViewController: UIViewController {
GalleryConfigurationItem.overlayColor(UIColor(white: 0.035, alpha: 1)),
GalleryConfigurationItem.overlayColorOpacity(1),
GalleryConfigurationItem.overlayBlurOpacity(1),
GalleryConfigurationItem.overlayBlurStyle(UIBlurEffectStyle.light),
GalleryConfigurationItem.overlayBlurStyle(UIBlurEffect.Style.light),

GalleryConfigurationItem.videoControlsColor(.white),

Expand Down
14 changes: 9 additions & 5 deletions ImageViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = MailOnline;
TargetAttributes = {
C7897CE11C1350B7006447FB = {
Expand Down Expand Up @@ -652,7 +652,7 @@
PRODUCT_BUNDLE_IDENTIFIER = mailonline.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -666,7 +666,7 @@
PRODUCT_BUNDLE_IDENTIFIER = mailonline.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -683,12 +683,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -741,12 +743,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -796,7 +800,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -815,7 +819,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -37,7 +36,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 2 additions & 2 deletions ImageViewer/Source/Extensions/CAShapeLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ extension CAShapeLayer {
let elementBorder = CAShapeLayer()
elementBorder.bounds.size = CGSize(width: edgeLength, height: edgeLength)
elementBorder.position = CGPoint(x: container.bounds.midX, y: container.bounds.midY)
elementBorder.lineCap = kCALineCapRound
elementBorder.lineCap = CAShapeLayerLineCap.round
elementBorder.path = linePath.cgPath
elementBorder.strokeColor = UIColor.darkGray.cgColor
elementBorder.lineWidth = 2.5

let elementFill = CAShapeLayer()
elementFill.bounds.size = CGSize(width: edgeLength, height: edgeLength)
elementFill.position = CGPoint(x: container.bounds.midX, y: container.bounds.midY)
elementFill.lineCap = kCALineCapRound
elementFill.lineCap = CAShapeLayerLineCap.round
elementFill.path = linePath.cgPath
elementFill.strokeColor = UIColor.white.cgColor
elementFill.lineWidth = 2
Expand Down
10 changes: 5 additions & 5 deletions ImageViewer/Source/Extensions/UISlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Slider {

let slider = Slider(frame: CGRect(x: 0, y: 0, width: width, height: height))

slider.setThumbImage(CAShapeLayer.circle(UIColor.white, diameter: pointerDiameter).toImage(), for: UIControlState())
slider.setThumbImage(CAShapeLayer.circle(UIColor.white, diameter: pointerDiameter).toImage(), for: UIControl.State())

let tileImageFrame = CGRect(origin: CGPoint.zero, size: CGSize(width: 1, height: barHeight))

Expand All @@ -26,8 +26,8 @@ extension Slider {
maxTrackImage.backgroundColor = UIColor.darkGray.cgColor
maxTrackImage.frame = tileImageFrame

slider.setMinimumTrackImage(minTrackImage.toImage(), for: UIControlState())
slider.setMaximumTrackImage(maxTrackImage.toImage(), for: UIControlState())
slider.setMinimumTrackImage(minTrackImage.toImage(), for: UIControl.State())
slider.setMaximumTrackImage(maxTrackImage.toImage(), for: UIControl.State())

return slider
}
Expand All @@ -37,7 +37,7 @@ extension Slider {
self.maximumTrackTintColor = self.tintColor.shadeDarker()

// Correct way would be setting self.thumbTintColor however this has a bug which changes the thumbImage frame
let image = self.currentThumbImage?.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
self.setThumbImage(image, for: UIControlState.normal)
let image = self.currentThumbImage?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
self.setThumbImage(image, for: UIControl.State.normal)
}
}
4 changes: 2 additions & 2 deletions ImageViewer/Source/Extensions/UIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ extension UIView {

static func animateWithDuration(_ duration: TimeInterval, delay: TimeInterval, animations: @escaping () -> Void) {

UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions(), animations: animations, completion: nil)
UIView.animate(withDuration: duration, delay: delay, options: UIView.AnimationOptions(), animations: animations, completion: nil)
}

static func animateWithDuration(_ duration: TimeInterval, delay: TimeInterval, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) {

UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions(), animations: animations, completion: completion)
UIView.animate(withDuration: duration, delay: delay, options: UIView.AnimationOptions(), animations: animations, completion: completion)
}
}

Expand Down
6 changes: 3 additions & 3 deletions ImageViewer/Source/GalleryConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public enum GalleryConfigurationItem {
case deleteLayout(ButtonLayout)

/// This spinner is shown when we page to an image page, but the image itself is still loading.
case spinnerStyle(UIActivityIndicatorViewStyle)
case spinnerStyle(UIActivityIndicatorView.Style)

/// Tint color for the spinner.
case spinnerColor(UIColor)
Expand Down Expand Up @@ -121,7 +121,7 @@ public enum GalleryConfigurationItem {
case displacementKeepOriginalInPlace(Bool)

///Provides the most typical timing curves for the displacement transition.
case displacementTimingCurve(UIViewAnimationCurve)
case displacementTimingCurve(UIView.AnimationCurve)

///Allows to optionally set a spring bounce when the displacement transition finishes.
case displacementTransitionStyle(GalleryDisplacementStyle)
Expand All @@ -133,7 +133,7 @@ public enum GalleryConfigurationItem {
case overlayColor(UIColor)

///Allows to select the overall tone on the B&W scale of the blur layer in the overlay.
case overlayBlurStyle(UIBlurEffectStyle)
case overlayBlurStyle(UIBlurEffect.Style)

///The opacity of overlay layer when the displacement effect finishes anf the gallery is fully presented. Valid values are from 0 to 1 where 1 is full opacity i.e the overlay layer is fully opaque, 0 is completely transparent and effectively invisible.
case overlayBlurOpacity(CGFloat)
Expand Down
2 changes: 1 addition & 1 deletion ImageViewer/Source/GalleryDisplacedViewsDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public protocol DisplaceableView {
var bounds: CGRect { get }
var center: CGPoint { get }
var boundsCenter: CGPoint { get }
var contentMode: UIViewContentMode { get }
var contentMode: UIView.ContentMode { get }
var isHidden: Bool { get set }

func convert(_ point: CGPoint, to view: UIView?) -> CGPoint
Expand Down
6 changes: 3 additions & 3 deletions ImageViewer/Source/GallerySwipeToDismissTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ final class GallerySwipeToDismissTransition {

/// In units of "vertical velocity". For example if we have a vertical velocity of 50 units (which are points really) per second
/// and the distance to travel is 175 units, then our spring velocity is 3.5. I.e. we will travel 3.5 units in 1 second.
let springVelocity = fabs(escapeVelocity / (targetOffset - touchPoint))
let springVelocity = abs(escapeVelocity / (targetOffset - touchPoint))

/// How much time it will take to travel the remaining distance given the above speed.
let expectedDuration = TimeInterval( fabs(targetOffset - touchPoint) / fabs(escapeVelocity))
let expectedDuration = TimeInterval( abs(targetOffset - touchPoint) / abs(escapeVelocity))

UIView.animate(withDuration: expectedDuration * 0.65, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: springVelocity, options: UIViewAnimationOptions.curveLinear, animations: { [weak self] () -> Void in
UIView.animate(withDuration: expectedDuration * 0.65, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: springVelocity, options: UIView.AnimationOptions.curveLinear, animations: { [weak self] () -> Void in

switch swipeDirection {

Expand Down
24 changes: 12 additions & 12 deletions ImageViewer/Source/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {

pagingDataSource = GalleryPagingDataSource(itemsDataSource: itemsDataSource, displacedViewsDataSource: displacedViewsDataSource, scrubber: scrubber, configuration: configuration)

super.init(transitionStyle: UIPageViewControllerTransitionStyle.scroll,
navigationOrientation: UIPageViewControllerNavigationOrientation.horizontal,
options: [UIPageViewControllerOptionInterPageSpacingKey : NSNumber(value: spineDividerWidth as Float)])
super.init(transitionStyle: UIPageViewController.TransitionStyle.scroll,
navigationOrientation: UIPageViewController.NavigationOrientation.horizontal,
options: [UIPageViewController.OptionsKey.interPageSpacing : NSNumber(value: spineDividerWidth as Float)])

pagingDataSource.itemControllerDelegate = self

///This feels out of place, one would expect even the first presented(paged) item controller to be provided by the paging dataSource but there is nothing we can do as Apple requires the first controller to be set via this "setViewControllers" method.
let initialController = pagingDataSource.createItemController(startIndex, isInitial: true)
self.setViewControllers([initialController], direction: UIPageViewControllerNavigationDirection.forward, animated: false, completion: nil)
self.setViewControllers([initialController], direction: UIPageViewController.NavigationDirection.forward, animated: false, completion: nil)

if let controller = initialController as? ItemController {

Expand All @@ -169,9 +169,9 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {
self.modalPresentationStyle = .overFullScreen
self.dataSource = pagingDataSource

UIApplication.applicationWindow.windowLevel = (statusBarHidden) ? UIWindowLevelStatusBar + 1 : UIWindowLevelNormal
UIApplication.applicationWindow.windowLevel = (statusBarHidden) ? UIWindow.Level.statusBar + 1 : UIWindow.Level.normal

NotificationCenter.default.addObserver(self, selector: #selector(GalleryViewController.rotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(GalleryViewController.rotate), name: UIDevice.orientationDidChangeNotification, object: nil)

if continueNextVideoOnFinish {
NotificationCenter.default.addObserver(self, selector: #selector(didEndPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
Expand All @@ -194,7 +194,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {
overlayView.center = CGPoint(x: (UIScreen.main.bounds.width / 2), y: (UIScreen.main.bounds.height / 2))

self.view.addSubview(overlayView)
self.view.sendSubview(toBack: overlayView)
self.view.sendSubviewToBack(overlayView)
}

fileprivate func configureHeaderView() {
Expand Down Expand Up @@ -448,7 +448,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {
thumbnailsController.closeLayout = seeAllCloseLayout
} else if let closeButton = closeButton {
let seeAllCloseButton = UIButton(frame: CGRect(origin: CGPoint.zero, size: closeButton.bounds.size))
seeAllCloseButton.setImage(closeButton.image(for: UIControlState()), for: UIControlState())
seeAllCloseButton.setImage(closeButton.image(for: UIControl.State()), for: UIControl.State())
seeAllCloseButton.setImage(closeButton.image(for: .highlighted), for: .highlighted)
thumbnailsController.closeButton = seeAllCloseButton
thumbnailsController.closeLayout = closeLayout
Expand All @@ -467,7 +467,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {
guard currentIndex != index && index >= 0 && index < self.itemsDataSource.itemCount() else { return }

let imageViewController = self.pagingDataSource.createItemController(index)
let direction: UIPageViewControllerNavigationDirection = index > currentIndex ? .forward : .reverse
let direction: UIPageViewController.NavigationDirection = index > currentIndex ? .forward : .reverse

// workaround to make UIPageViewController happy
if direction == .forward {
Expand All @@ -491,7 +491,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {

// If removing last item, go back, otherwise, go forward

let direction: UIPageViewControllerNavigationDirection = index < self.itemsDataSource.itemCount() ? .forward : .reverse
let direction: UIPageViewController.NavigationDirection = index < self.itemsDataSource.itemCount() ? .forward : .reverse

let newIndex = direction == .forward ? index : index - 1

Expand Down Expand Up @@ -525,7 +525,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {

isAnimating = true

UIView.animate(withDuration: rotationDuration, delay: 0, options: UIViewAnimationOptions.curveLinear, animations: { [weak self] () -> Void in
UIView.animate(withDuration: rotationDuration, delay: 0, options: UIView.AnimationOptions.curveLinear, animations: { [weak self] () -> Void in

self?.view.transform = windowRotationTransform()
self?.view.bounds = rotationAdjustedBounds()
Expand Down Expand Up @@ -596,7 +596,7 @@ open class GalleryViewController: UIPageViewController, ItemControllerDelegate {

self.dismiss(animated: animated) {

UIApplication.applicationWindow.windowLevel = UIWindowLevelNormal
UIApplication.applicationWindow.windowLevel = UIWindow.Level.normal
completion?()
}
}
Expand Down
Loading

0 comments on commit ffe41df

Please sign in to comment.