Skip to content

Commit aa0e4c2

Browse files
jfahrenkrugRuiAAPeres
authored andcommitted
Upgrade to Swift 5 (#224)
* 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
1 parent 9afa043 commit aa0e4c2

File tree

11 files changed

+43
-20
lines changed

11 files changed

+43
-20
lines changed

.swift-version

-1
This file was deleted.

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
osx_image: xcode10
1+
osx_image: xcode11
22
language: objective-c
33

44
script:
55
- set -o pipefail
6-
- xcodebuild build -scheme ImageViewer -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 6s" | xcpretty -c
6+
- xcodebuild build -scheme ImageViewer -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" | xcpretty -c

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ImageViewer
22

3+
## Version 6.0.0
4+
5+
* Upgrade to Swift 5 and fix subsequent compiler warnings
6+
37
## Version 4.1.0
48

59
* Autoplay video ([PR #120](https://github.com/MailOnline/ImageViewer/pull/120)).

Example/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ViewController: UIViewController {
6969

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

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

7474
let frame = CGRect(x: 0, y: 0, width: 200, height: 24)
7575
let headerView = CounterView(frame: frame, currentIndex: displacedViewIndex, count: items.count)

ImageViewer.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ImageViewer"
3-
s.version = "5.0.0"
3+
s.version = "6.0.0"
44
s.summary = "An image viewer à la Twitter"
55
s.description = <<-EOS
66
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.

ImageViewer.xcodeproj/project.pbxproj

+9-9
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@
460460
TargetAttributes = {
461461
C7897CE11C1350B7006447FB = {
462462
CreatedOnToolsVersion = 7.1.1;
463-
LastSwiftMigration = 0900;
463+
LastSwiftMigration = 1100;
464464
};
465465
C7DABE471C12245B00F5BD7B = {
466466
CreatedOnToolsVersion = 7.1.1;
467-
LastSwiftMigration = 0900;
467+
LastSwiftMigration = 1100;
468468
};
469469
EB1CEC121C84A4EE00BB27B8 = {
470470
CreatedOnToolsVersion = 7.2.1;
@@ -473,7 +473,7 @@
473473
};
474474
buildConfigurationList = C7DABE421C12245B00F5BD7B /* Build configuration list for PBXProject "ImageViewer" */;
475475
compatibilityVersion = "Xcode 3.2";
476-
developmentRegion = English;
476+
developmentRegion = en;
477477
hasScannedForEncodings = 0;
478478
knownRegions = (
479479
en,
@@ -652,7 +652,7 @@
652652
PRODUCT_BUNDLE_IDENTIFIER = mailonline.Example;
653653
PRODUCT_NAME = "$(TARGET_NAME)";
654654
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
655-
SWIFT_VERSION = 4.2;
655+
SWIFT_VERSION = 5.0;
656656
};
657657
name = Debug;
658658
};
@@ -666,7 +666,7 @@
666666
PRODUCT_BUNDLE_IDENTIFIER = mailonline.Example;
667667
PRODUCT_NAME = "$(TARGET_NAME)";
668668
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
669-
SWIFT_VERSION = 4.2;
669+
SWIFT_VERSION = 5.0;
670670
};
671671
name = Release;
672672
};
@@ -723,7 +723,7 @@
723723
ONLY_ACTIVE_ARCH = YES;
724724
SDKROOT = iphoneos;
725725
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
726-
SWIFT_VERSION = 3.0;
726+
SWIFT_VERSION = 5.0;
727727
TARGETED_DEVICE_FAMILY = "1,2";
728728
VERSIONING_SYSTEM = "apple-generic";
729729
VERSION_INFO_PREFIX = "";
@@ -777,7 +777,7 @@
777777
MTL_ENABLE_DEBUG_INFO = NO;
778778
SDKROOT = iphoneos;
779779
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
780-
SWIFT_VERSION = 3.0;
780+
SWIFT_VERSION = 5.0;
781781
TARGETED_DEVICE_FAMILY = "1,2";
782782
VALIDATE_PRODUCT = YES;
783783
VERSIONING_SYSTEM = "apple-generic";
@@ -800,7 +800,7 @@
800800
PRODUCT_NAME = "$(TARGET_NAME)";
801801
SKIP_INSTALL = YES;
802802
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
803-
SWIFT_VERSION = 4.2;
803+
SWIFT_VERSION = 5.0;
804804
};
805805
name = Debug;
806806
};
@@ -819,7 +819,7 @@
819819
PRODUCT_NAME = "$(TARGET_NAME)";
820820
SKIP_INSTALL = YES;
821821
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
822-
SWIFT_VERSION = 4.2;
822+
SWIFT_VERSION = 5.0;
823823
};
824824
name = Release;
825825
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

ImageViewer/Source/Extensions/UIScreen.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010

1111
public extension UIScreen {
12-
public class var hasNotch: Bool {
12+
class var hasNotch: Bool {
1313
// This will of course fail if Apple produces an notchless iPhone with these dimensions,
1414
// but is the simplest detection mechanism so far.
1515
return main.nativeBounds.size == CGSize(width: 1125, height: 2436)

ImageViewer/Source/Extensions/UIViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
public extension UIViewController {
1212

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

1515
present(gallery, animated: false, completion: completion)
1616
}

ImageViewer/Source/VideoScrubber.swift

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ open class VideoScrubber: UIControl {
2020
var duration: TimeInterval?
2121
fileprivate var periodicObserver: AnyObject?
2222
fileprivate var stoppedSlidingTimeStamp = Date()
23+
24+
/// The attributes dictionary used for the timeLabel
25+
fileprivate var timeLabelAttributes: [NSAttributedString.Key : Any] {
26+
var attributes: [NSAttributedString.Key : Any] = [NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)]
27+
28+
if let tintColor = tintColor {
29+
attributes[NSAttributedString.Key.foregroundColor] = tintColor
30+
}
31+
32+
return attributes
33+
}
2334

2435
weak var player: AVPlayer? {
2536

@@ -106,7 +117,7 @@ open class VideoScrubber: UIControl {
106117
scrubber.maximumValue = 1000
107118
scrubber.value = 0
108119

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

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

239250
let timeString = stringFromTimeInterval(currentTime as TimeInterval)
240251

241-
timeLabel.attributedText = NSAttributedString(string: timeString, attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
252+
timeLabel.attributedText = NSAttributedString(string: timeString, attributes: timeLabelAttributes)
242253
}
243254
else {
244-
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: [NSAttributedString.Key.foregroundColor : self.tintColor, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)])
255+
timeLabel.attributedText = NSAttributedString(string: "--:--", attributes: timeLabelAttributes)
245256
}
246257
}
247258

@@ -258,7 +269,7 @@ open class VideoScrubber: UIControl {
258269
}
259270

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

263274
let playButtonImage = playButton.imageView?.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
264275
playButton.imageView?.tintColor = self.tintColor

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ If you use earlier version of Swift - refer to the table below:
5555

5656
| Swift version | ImageViewer version |
5757
| ------------- | --------------------------------- |
58+
| 5.x | >= 6.0 |
5859
| 4.x | >= 5.0 |
5960
| 3.x | 4.0 |
6061
| 2.3 | 3.1 [⚠️](CHANGELOG.md#version-31) |

0 commit comments

Comments
 (0)