瀏覽代碼

Migrate to Swift 4.2

CircleCI: Bump for Swift 4.2

Fastlane: Update tvOS Simulator version
Soomin Lee 6 年之前
父節點
當前提交
1a6585be2b

+ 1 - 2
.circleci/config.yml

@@ -3,14 +3,13 @@ version: 2
 jobs:
   build:
     macos:
-      xcode: "9.3.0"
+      xcode: "10.1.0"
     environment:
       LC_ALL: en_US.UTF-8
       LANG: en_US.UTF-8
     shell: /bin/bash --login -eo pipefail
     steps:
       - checkout
-      - run: echo "2.3.7" > .ruby-version
       - restore_cache:
           key: v1-gems-{{ checksum "Gemfile.lock" }}
       - run: bundle check || bundle install --path .bundle

+ 2 - 2
SharedSources/VLCAlertViewController.swift

@@ -16,9 +16,9 @@ typealias AlertAction = (UIAlertAction) -> Void
 
 @objcMembers class VLCAlertButton: NSObject {
     let title: String
-    let style: UIAlertActionStyle
+    let style: UIAlertAction.Style
     let action: AlertAction?
-    init(title: String, style: UIAlertActionStyle = .default, action: AlertAction? = nil) {
+    init(title: String, style: UIAlertAction.Style = .default, action: AlertAction? = nil) {
         self.title = title
         self.style = style
         self.action = action

+ 4 - 4
Sources/AppearanceManager.swift

@@ -21,18 +21,18 @@ class AppearanceManager: NSObject {
         UITextField.appearance().tintColor = theme.colors.orangeUI
 
         // Don't override the 'Cancel' button color in the search bar with the previous UITextField call. Use the default blue color
-        let attributes = [NSAttributedStringKey.foregroundColor: theme.colors.orangeUI]
+        let attributes = [NSAttributedString.Key.foregroundColor: theme.colors.orangeUI]
         UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)
 
         UINavigationBar.appearance().barTintColor = theme.colors.navigationbarColor
         UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).barTintColor = nil
         UINavigationBar.appearance().tintColor = theme.colors.orangeUI
-        UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: theme.colors.navigationbarTextColor]
+        UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
 
         if #available(iOS 11.0, *) {
             UINavigationBar.appearance().prefersLargeTitles = true
             UINavigationBar.appearance(whenContainedInInstancesOf: [VLCPlaybackNavigationController.self]).prefersLargeTitles = false
-            UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: theme.colors.navigationbarTextColor]
+            UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: theme.colors.navigationbarTextColor]
         }
         // For the edit selection indicators
         UITableView.appearance().tintColor = theme.colors.orangeUI
@@ -46,7 +46,7 @@ class AppearanceManager: NSObject {
 
 //extensions so that preferredStatusBarStyle is called on all childViewControllers otherwise this is not forwarded
 extension UINavigationController {
-    override open var childViewControllerForStatusBarStyle: UIViewController? {
+    override open var childForStatusBarStyle: UIViewController? {
         return self.topViewController
     }
 }

+ 8 - 5
Sources/Coordinators/AppCoordinator.swift

@@ -36,16 +36,19 @@ class Services: NSObject {
     }
 
     private func setupChildViewControllers() {
-        viewController.addChildViewController(tabBarController)
+        viewController.addChild(tabBarController)
         viewController.view.addSubview(tabBarController.view)
         tabBarController.view.frame = viewController.view.frame
-        tabBarController.didMove(toParentViewController: viewController)
+        tabBarController.didMove(toParent: viewController)
 
-        viewController.addChildViewController(playerController)
+        viewController.addChild(playerController)
         viewController.view.addSubview(playerController.view)
-        playerController.view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: tabBarController.tabBar.frame.size.height, right: 0)
+        playerController.view.layoutMargins = UIEdgeInsets(top: 0,
+                                                           left: 0,
+                                                           bottom: tabBarController.tabBar.frame.size.height,
+                                                           right: 0)
         playerController.realBottomAnchor = tabBarController.tabBar.topAnchor
-        playerController.didMove(toParentViewController: viewController)
+        playerController.didMove(toParent: viewController)
     }
 
     @objc func start() {

+ 1 - 1
Sources/KeychainCoordinator.swift

@@ -57,7 +57,7 @@ class KeychainCoordinator: NSObject, PAPasscodeViewControllerDelegate {
 
     override init() {
         super.init()
-        NotificationCenter.default.addObserver(self, selector: #selector(appInForeground), name: .UIApplicationDidBecomeActive, object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(appInForeground), name: UIApplication.didBecomeActiveNotification, object: nil)
     }
 
     @objc class func setPasscode(passcode: String?) throws {

+ 1 - 1
Sources/LocalNetworkConnectivity/RemoteNetworkCell.swift

@@ -15,7 +15,7 @@ import UIKit
 class VLCRemoteNetworkCell: UITableViewCell {
     @objc static let cellIdentifier = "RemoteNetworkCell"
 
-    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
+    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
         super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
         commonInit()
     }

+ 12 - 12
Sources/PagerStripViewController.swift

@@ -75,16 +75,16 @@ class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
         reloadViewControllers()
 
         let childController = viewControllers[currentIndex]
-        addChildViewController(childController)
+        addChild(childController)
         childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
         containerView.addSubview(childController.view)
-        childController.didMove(toParentViewController: self)
+        childController.didMove(toParent: self)
     }
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         isViewAppearing = true
-        childViewControllers.forEach { $0.beginAppearanceTransition(true, animated: animated) }
+        children.forEach { $0.beginAppearanceTransition(true, animated: animated) }
     }
 
     override func viewDidAppear(_ animated: Bool) {
@@ -96,17 +96,17 @@ class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
             moveToViewController(at: preCurrentIndex)
         }
         isViewAppearing = false
-        childViewControllers.forEach { $0.endAppearanceTransition() }
+        children.forEach { $0.endAppearanceTransition() }
     }
 
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
-        childViewControllers.forEach { $0.beginAppearanceTransition(false, animated: animated) }
+        children.forEach { $0.beginAppearanceTransition(false, animated: animated) }
     }
 
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
-        childViewControllers.forEach { $0.endAppearanceTransition() }
+        children.forEach { $0.endAppearanceTransition() }
     }
 
     override func viewDidLayoutSubviews() {
@@ -220,19 +220,19 @@ class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
                     childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
                 } else {
                     childController.beginAppearanceTransition(true, animated: false)
-                    addChildViewController(childController)
+                    addChild(childController)
                     childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
                     childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
                     containerView.addSubview(childController.view)
-                    childController.didMove(toParentViewController: self)
+                    childController.didMove(toParent: self)
                     childController.endAppearanceTransition()
                 }
             } else {
                 if childController.parent != nil {
                     childController.beginAppearanceTransition(false, animated: false)
-                    childController.willMove(toParentViewController: nil)
+                    childController.willMove(toParent: nil)
                     childController.view.removeFromSuperview()
-                    childController.removeFromParentViewController()
+                    childController.removeFromParent()
                     childController.endAppearanceTransition()
                 }
             }
@@ -256,9 +256,9 @@ class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
         guard isViewLoaded else { return }
         for childController in viewControllers where childController.parent != nil {
             childController.beginAppearanceTransition(false, animated: false)
-            childController.willMove(toParentViewController: nil)
+            childController.willMove(toParent: nil)
             childController.view.removeFromSuperview()
-            childController.removeFromParentViewController()
+            childController.removeFromParent()
             childController.endAppearanceTransition()
         }
         reloadViewControllers()

+ 20 - 15
Sources/URLHandler.swift

@@ -13,8 +13,8 @@
 import Foundation
 
 @objc public protocol VLCURLHandler {
-    func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool
-    func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool
+    func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool
+    func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool
 }
 
 @objc class URLHandlers: NSObject {
@@ -33,11 +33,11 @@ import Foundation
 
 class DropBoxURLHandler: NSObject, VLCURLHandler {
 
-    @objc func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return url.scheme == "db-a60fc6qj9zdg7bw"
     }
 
-    @objc func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         let authResult = DBClientsManager.handleRedirectURL(url)
 
         if  let authResult = authResult, authResult.isSuccess() == true {
@@ -52,11 +52,11 @@ class GoogleURLHandler: NSObject, VLCURLHandler {
 
     @objc var currentGoogleAuthorizationFlow: OIDAuthorizationFlowSession?
 
-    @objc func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return url.scheme == "com.googleusercontent.apps.CLIENT"
     }
 
-    @objc func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         if currentGoogleAuthorizationFlow?.resumeAuthorizationFlow(with: url) == true {
             currentGoogleAuthorizationFlow = nil
             return true
@@ -67,11 +67,11 @@ class GoogleURLHandler: NSObject, VLCURLHandler {
 
 class FileURLHandler: NSObject, VLCURLHandler {
 
-    @objc func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return url.isFileURL
     }
 
-    @objc func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         let subclass = DocumentClass(fileURL: url)
         subclass.open { _ in
             self.play(url: url) { _ in
@@ -84,11 +84,11 @@ class FileURLHandler: NSObject, VLCURLHandler {
 
 class XCallbackURLHandler: NSObject, VLCURLHandler {
 
-    @objc func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return url.scheme == "vlc-x-callback" || url.scheme == "x-callback-url"
     }
 
-    @objc func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         let action = url.path.replacingOccurrences(of: "/", with: "")
         var movieURL: URL?
         var successCallback: URL?
@@ -125,7 +125,7 @@ class XCallbackURLHandler: NSObject, VLCURLHandler {
                     return
                 }
                 if #available(iOS 10, *) {
-                    UIApplication.shared.open(callback, options: [:], completionHandler: nil)
+                    UIApplication.shared.open(callback, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
                 } else {
                     UIApplication.shared.openURL(callback)
                 }
@@ -141,7 +141,7 @@ class XCallbackURLHandler: NSObject, VLCURLHandler {
 
 public class VLCCallbackURLHandler: NSObject, VLCURLHandler {
 
-    @objc public func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc public func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return url.scheme == "vlc"
     }
 
@@ -156,7 +156,7 @@ public class VLCCallbackURLHandler: NSObject, VLCURLHandler {
         return URL(string: parsedString)!
     }
 
-    public func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    public func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
 
         let transformedURL = transformVLCURL(url)
         let scheme = transformedURL.scheme
@@ -179,11 +179,11 @@ public class VLCCallbackURLHandler: NSObject, VLCURLHandler {
 }
 
 class ElseCallbackURLHandler: NSObject, VLCURLHandler {
-    @objc func canHandleOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    @objc func canHandleOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         return true
     }
 
-    func performOpen(url: URL, options: [UIApplicationOpenURLOptionsKey: AnyObject]) -> Bool {
+    func performOpen(url: URL, options: [UIApplication.OpenURLOptionsKey: AnyObject]) -> Bool {
         self.play(url: url, completion: nil)
         return true
     }
@@ -203,3 +203,8 @@ extension VLCURLHandler {
         VLCDownloadViewController.sharedInstance().addURL(toDownloadList: url, fileNameOfMedia: fileName)
     }
 }
+
+// Helper function inserted by Swift 4.2 migrator.
+fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
+	return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
+}

+ 2 - 2
Sources/VLCTabBarCoordinator.swift

@@ -34,10 +34,10 @@ class VLCTabBarCoordinator: NSObject {
             if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
                 navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
                 navController.navigationBar.tintColor = PresentationTheme.current.colors.orangeUI
-                navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]
+                navController.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]
 
                 if #available(iOS 11.0, *) {
-                    navController.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]
+                    navController.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]
                 }
             }
         }

+ 12 - 6
VLC.xcodeproj/project.pbxproj

@@ -2558,13 +2558,14 @@
 					41533C90211338D500EC3ABA = {
 						CreatedOnToolsVersion = 9.4.1;
 						DevelopmentTeam = 75GAHG3SZQ;
-						LastSwiftMigration = 0940;
+						LastSwiftMigration = 1000;
 						ProvisioningStyle = Automatic;
 						TestTargetID = 7D94FCDA16DE7D1000F2623B;
 					};
 					41B0BC851F73ED7D0063BA26 = {
 						CreatedOnToolsVersion = 9.0;
 						DevelopmentTeam = 75GAHG3SZQ;
+						LastSwiftMigration = 1000;
 						ProvisioningStyle = Automatic;
 						TestTargetID = 7D94FCDA16DE7D1000F2623B;
 					};
@@ -2586,7 +2587,7 @@
 					};
 					7D94FCDA16DE7D1000F2623B = {
 						DevelopmentTeam = 75GAHG3SZQ;
-						LastSwiftMigration = 0920;
+						LastSwiftMigration = 1000;
 						SystemCapabilities = {
 							com.apple.ApplicationGroups.iOS = {
 								enabled = 1;
@@ -3460,7 +3461,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
-				SWIFT_VERSION = 4.0;
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VLC for iOS.app/VLC for iOS";
 				TEST_TARGET_NAME = "VLC-iOS";
@@ -3497,7 +3498,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = "org.example.com.VLC-iOSTests";
 				PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				SWIFT_VERSION = 4.0;
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VLC for iOS.app/VLC for iOS";
 				TEST_TARGET_NAME = VLC;
@@ -3534,7 +3535,7 @@
 				PRODUCT_BUNDLE_IDENTIFIER = "org.example.com.VLC-iOSTests";
 				PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
-				SWIFT_VERSION = 4.0;
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VLC for iOS.app/VLC for iOS";
 				TEST_TARGET_NAME = "VLC-iOS";
@@ -3586,6 +3587,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-UITests/VLC-iOSUITest-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_TARGET_NAME = "VLC-iOS";
 			};
@@ -3638,6 +3640,7 @@
 				SWIFT_COMPILATION_MODE = singlefile;
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-UITests/VLC-iOSUITest-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_TARGET_NAME = "VLC-iOS";
 			};
@@ -3689,6 +3692,7 @@
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-UITests/VLC-iOSUITest-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 4.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 				TEST_TARGET_NAME = "VLC-iOS";
 			};
@@ -3962,6 +3966,7 @@
 				SKIP_INSTALL = NO;
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+				SWIFT_VERSION = 4.2;
 				VALID_ARCHS = "arm64 armv7 armv7s";
 			};
 			name = Debug;
@@ -4006,6 +4011,7 @@
 				SWIFT_COMPILATION_MODE = singlefile;
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+				SWIFT_VERSION = 4.2;
 				VALID_ARCHS = "arm64 armv7 armv7s";
 			};
 			name = Release;
@@ -4097,7 +4103,7 @@
 				SKIP_INSTALL = NO;
 				SWIFT_OBJC_BRIDGING_HEADER = "VLC-iOS-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
-				SWIFT_VERSION = 4.0;
+				SWIFT_VERSION = 4.2;
 				VALID_ARCHS = "arm64 armv7 armv7s";
 			};
 			name = Distribution;

+ 1 - 1
fastlane/Fastfile

@@ -58,7 +58,7 @@ lane :ci do
     configuration: 'Debug',
     clean: true,
     build: true,
-    destination: 'platform=tvOS Simulator,name=Apple TV,OS=11.3'
+    destination: 'platform=tvOS Simulator,name=Apple TV,OS=11.2'
   )
   test
 end