Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #133 from 3lvis/swift5
Browse files Browse the repository at this point in the history
Swift5
  • Loading branch information
3lvis authored Apr 17, 2019
2 parents 6242332 + baaf8ca commit f7b26fc
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
5.0
36 changes: 19 additions & 17 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,31 +400,31 @@
attributes = {
CLASSPREFIX = "";
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 1010;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "";
TargetAttributes = {
146D72AB1AB782920058798C = {
CreatedOnToolsVersion = 6.2;
DevelopmentTeamName = "Elvis Nuñez AS";
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
14C983FC1C0DE79200B5E515 = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeamName = "Elvis Nuñez AS";
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
14E5F75E1E7831AF00D970EF = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
};
};
buildConfigurationList = 146D728E1AB782920058798C /* Build configuration list for PBXProject "Demo" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -599,6 +599,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -652,6 +653,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -698,6 +700,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = "";
Expand All @@ -711,15 +714,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
146D72BB1AB782920058798C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
FRAMEWORK_SEARCH_PATHS = "";
Expand All @@ -729,8 +732,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -739,6 +741,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand All @@ -752,8 +755,7 @@
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -763,6 +765,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
Expand All @@ -775,8 +778,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -788,6 +790,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = "";
Expand All @@ -799,8 +802,7 @@
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.0;
};
Expand All @@ -813,6 +815,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
Expand All @@ -823,8 +826,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.0;
};
Expand Down
2 changes: 1 addition & 1 deletion Demo.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Demo.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Demo.xcodeproj/xcshareddata/xcschemes/tvOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
37 changes: 20 additions & 17 deletions Library/PhotosCollectionLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ import UIKit
class PhotosCollectionLayout: UICollectionViewFlowLayout {
static let headerSize = CGFloat(69)
class var numberOfColumns: Int {

#if os(iOS)
var isPortrait: Bool
switch UIDevice.current.orientation {
case .portrait, .portraitUpsideDown, .unknown, .faceUp, .faceDown:
isPortrait = true
case .landscapeLeft, .landscapeRight:
isPortrait = false
}

var numberOfColumns = 0
if UIDevice.current.userInterfaceIdiom == .phone {
numberOfColumns = isPortrait ? 3 : 6
} else {
numberOfColumns = isPortrait ? 5 : 8
}

return numberOfColumns
var isPortrait: Bool = false
switch UIDevice.current.orientation {
case .portrait, .portraitUpsideDown, .unknown, .faceUp, .faceDown:
isPortrait = true
case .landscapeLeft, .landscapeRight:
isPortrait = false
@unknown default:
break
}

var numberOfColumns = 0
if UIDevice.current.userInterfaceIdiom == .phone {
numberOfColumns = isPortrait ? 3 : 6
} else {
numberOfColumns = isPortrait ? 5 : 8
}

return numberOfColumns
#else
return 6
return 6
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Library/PhotosController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class PhotosController: UICollectionViewController {

#if os(tvOS)
let playPauseTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.playPause(gesture:)))
playPauseTapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
playPauseTapRecognizer.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
self.collectionView?.addGestureRecognizer(playPauseTapRecognizer)

// Workaround for a bug where the collectionView won't select an item after dismissing the Viewer.
let selectTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.select(gesture:)))
selectTapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.select.rawValue)]
selectTapRecognizer.allowedPressTypes = [NSNumber(value: UIPress.PressType.select.rawValue)]
self.collectionView?.addGestureRecognizer(selectTapRecognizer)
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions Source/PaginatedScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class PaginatedScrollView: UIScrollView, ViewableControllerContainer {
self.showsVerticalScrollIndicator = false
self.delegate = self
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]

#if os(iOS)
self.decelerationRate = UIScrollView.DecelerationRate.fast
#endif
}

required init?(coder _: NSCoder) {
Expand Down
2 changes: 1 addition & 1 deletion Source/SlideshowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SlideshowView: UIView, ViewableControllerContainer {
}

func start() {
RunLoop.current.add(self.timer, forMode: .default)
RunLoop.current.add(self.timer, forMode: RunLoop.Mode.default)
}

func stop() {
Expand Down
6 changes: 3 additions & 3 deletions Source/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import UIKit

public extension UIView {
public convenience init(withAutoLayout autoLayout: Bool) {
convenience init(withAutoLayout autoLayout: Bool) {
self.init()
translatesAutoresizingMaskIntoConstraints = !autoLayout
}

public var compatibleTopAnchor: NSLayoutYAxisAnchor {
var compatibleTopAnchor: NSLayoutYAxisAnchor {
if #available(iOS 11.0, *) {
return safeAreaLayoutGuide.topAnchor
} else {
return topAnchor
}
}

public var compatibleBottomAnchor: NSLayoutYAxisAnchor {
var compatibleBottomAnchor: NSLayoutYAxisAnchor {
if #available(iOS 11.0, *) {
return safeAreaLayoutGuide.bottomAnchor
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/VideoProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class VideoProgressView: UIView {

public extension UILabel {

public func width() -> CGFloat {
func width() -> CGFloat {
let rect = (self.attributedText ?? NSAttributedString()).boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, context: nil)
return rect.width
}
Expand Down
12 changes: 7 additions & 5 deletions Source/VideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ class VideoView: UIView {
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) {

if keyPath == VideoView.audioSessionVolumeKeyPath {
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
} catch let error {
print("Failed to start playback sound: \(error.localizedDescription)")
}
#if os(iOS)
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
#endif
return
}

Expand Down Expand Up @@ -194,7 +192,9 @@ class VideoView: UIView {
self.playerLayer.player?.seek(to: CMTime.zero)
self.playerLayer.player = nil

#if os(iOS)
try? AVAudioSession.sharedInstance().setCategory(.soloAmbient, mode: .default, options: [])
#endif
}

func play() {
Expand Down Expand Up @@ -256,6 +256,8 @@ class VideoView: UIView {
self.actuallySeekToTime()
case .failed:
break
@unknown default:
break
}
}

Expand Down
10 changes: 5 additions & 5 deletions Source/ViewerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ public class ViewerController: UIViewController {
self.view.addSubview(self.scrollView)
#else
let menuTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.menu(gesture:)))
menuTapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.menu.rawValue)]
menuTapRecognizer.allowedPressTypes = [NSNumber(value: UIPress.PressType.menu.rawValue)]
self.view.addGestureRecognizer(menuTapRecognizer)

if self.isSlideshow {
self.view.addSubview(self.slideshowView)
} else {
self.addChildViewController(self.pageController)
self.addChild(self.pageController)
self.pageController.view.frame = UIScreen.main.bounds
self.view.addSubview(self.pageController.view)
self.pageController.didMove(toParentViewController: self)
self.pageController.didMove(toParent: self)

let playPauseTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.playPause(gesture:)))
playPauseTapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
playPauseTapRecognizer.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
self.view.addGestureRecognizer(playPauseTapRecognizer)

let selectTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.select(gesture:)))
selectTapRecognizer.allowedPressTypes = [NSNumber(value: UIPressType.select.rawValue)]
selectTapRecognizer.allowedPressTypes = [NSNumber(value: UIPress.PressType.select.rawValue)]
self.view.addGestureRecognizer(selectTapRecognizer)

let rightSwipeRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(rightSwipe(gesture:)))
Expand Down
2 changes: 1 addition & 1 deletion Viewer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Viewer"
s.summary = "Image viewer (or Lightbox) with support for local and remote videos and images"
s.version = "3.0.0"
s.version = "4.0.0"
s.homepage = "https://github.com/3lvis/Viewer"
s.license = 'MIT'
s.author = { "Elvis Nuñez" => "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
machine:
xcode:
version: "9.0"
version: "10.2"
4 changes: 2 additions & 2 deletions iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

public func application(_: UIApplication, willFinishLaunchingWithOptions _: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
public func application(_: UIApplication, willFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)

let localController = PhotosController(dataSourceType: .local)
Expand All @@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

if AppDelegate.IsLightStatusBar {
UINavigationBar.appearance().barTintColor = .orange
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
remoteNavigationController.navigationBar.barStyle = .black
localNavigationController.navigationBar.barStyle = .black
}
Expand Down
Loading

0 comments on commit f7b26fc

Please sign in to comment.