Skip to content

Commit

Permalink
Upgrade to Swift 5 (#224)
Browse files Browse the repository at this point in the history
* Upgrade to Swift 5

- Fix test target
- Upgrade everything to Swift 5
- Fix compiler warnings
- Small refactor in VideoScrubber to DRY up code and fix warnings
- Update .travis.yml for Xcode 11
- Remove obsolete .swift-version file
- Bump version to 6.0.0

* Fix .travis.yml to use iPhone 11 simulator
  • Loading branch information
jfahrenkrug authored and RuiAAPeres committed Oct 17, 2019
1 parent 9afa043 commit aa0e4c2
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 20 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
osx_image: xcode10
osx_image: xcode11
language: objective-c

script:
- set -o pipefail
- xcodebuild build -scheme ImageViewer -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 6s" | xcpretty -c
- xcodebuild build -scheme ImageViewer -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ImageViewer

## Version 6.0.0

* Upgrade to Swift 5 and fix subsequent compiler warnings

## Version 4.1.0

* Autoplay video ([PR #120](https://github.com/MailOnline/ImageViewer/pull/120)).
Expand Down
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ViewController: UIViewController {

guard let displacedView = sender.view as? UIImageView else { return }

guard let displacedViewIndex = items.index(where: { $0.imageView == displacedView }) else { return }
guard let displacedViewIndex = items.firstIndex(where: { $0.imageView == displacedView }) else { return }

let frame = CGRect(x: 0, y: 0, width: 200, height: 24)
let headerView = CounterView(frame: frame, currentIndex: displacedViewIndex, count: items.count)
Expand Down
2 changes: 1 addition & 1 deletion ImageViewer.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ImageViewer"
s.version = "5.0.0"
s.version = "6.0.0"
s.summary = "An image viewer à la Twitter"
s.description = <<-EOS
ImageViewer is a library that enables a user to visualize an image in fullscreen. Besides the typical pinch and double tap to zoom, we also provide a vertical swipe to dismiss. Finally, we try to mimic the displacement of the image from its current container into fullscreen, this feature being its main selling point. We also offer an amazing Gallery, so you can swipe between images.
Expand Down
18 changes: 9 additions & 9 deletions ImageViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@
TargetAttributes = {
C7897CE11C1350B7006447FB = {
CreatedOnToolsVersion = 7.1.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1100;
};
C7DABE471C12245B00F5BD7B = {
CreatedOnToolsVersion = 7.1.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1100;
};
EB1CEC121C84A4EE00BB27B8 = {
CreatedOnToolsVersion = 7.2.1;
Expand All @@ -473,7 +473,7 @@
};
buildConfigurationList = C7DABE421C12245B00F5BD7B /* Build configuration list for PBXProject "ImageViewer" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
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.2;
SWIFT_VERSION = 5.0;
};
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.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -723,7 +723,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -777,7 +777,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -800,7 +800,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -819,7 +819,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ImageViewer/Source/Extensions/UIScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

public extension UIScreen {
public class var hasNotch: Bool {
class var hasNotch: Bool {
// This will of course fail if Apple produces an notchless iPhone with these dimensions,
// but is the simplest detection mechanism so far.
return main.nativeBounds.size == CGSize(width: 1125, height: 2436)
Expand Down
2 changes: 1 addition & 1 deletion ImageViewer/Source/Extensions/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

public extension UIViewController {

public func presentImageGallery(_ gallery: GalleryViewController, completion: (() -> Void)? = {}) {
func presentImageGallery(_ gallery: GalleryViewController, completion: (() -> Void)? = {}) {

present(gallery, animated: false, completion: completion)
}
Expand Down
19 changes: 15 additions & 4 deletions ImageViewer/Source/VideoScrubber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ open class VideoScrubber: UIControl {
var duration: TimeInterval?
fileprivate var periodicObserver: AnyObject?
fileprivate var stoppedSlidingTimeStamp = Date()

/// The attributes dictionary used for the timeLabel
fileprivate var timeLabelAttributes: [NSAttributedString.Key : Any] {
var attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)]

if let tintColor = tintColor {
attributes[NSAttributedString.Key.foregroundColor] = tintColor
}

return attributes
}

weak var player: AVPlayer? {

Expand Down Expand Up @@ -106,7 +117,7 @@ open class VideoScrubber: UIControl {
scrubber.maximumValue = 1000
scrubber.value = 0

timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: timeLabelAttributes)
timeLabel.textAlignment = .center

playButton.addTarget(self, action: #selector(play), for: UIControl.Event.touchUpInside)
Expand Down Expand Up @@ -238,10 +249,10 @@ open class VideoScrubber: UIControl {

let timeString = stringFromTimeInterval(currentTime as TimeInterval)

timeLabel.attributedText = NSAttributedString(string: timeString, attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
timeLabel.attributedText = NSAttributedString(string: timeString, attributes: timeLabelAttributes)
}
else {
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: timeLabelAttributes)
}
}

Expand All @@ -258,7 +269,7 @@ open class VideoScrubber: UIControl {
}

override open func tintColorDidChange() {
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: timeLabelAttributes)

let playButtonImage = playButton.imageView?.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
playButton.imageView?.tintColor = self.tintColor
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ If you use earlier version of Swift - refer to the table below:

| Swift version | ImageViewer version |
| ------------- | --------------------------------- |
| 5.x | >= 6.0 |
| 4.x | >= 5.0 |
| 3.x | 4.0 |
| 2.3 | 3.1 [⚠️](CHANGELOG.md#version-31) |
Expand Down

0 comments on commit aa0e4c2

Please sign in to comment.