From 5c5931e86944d793eda6038fe5e8687a24afe460 Mon Sep 17 00:00:00 2001 From: Jon Andersen Date: Sun, 18 Nov 2018 20:40:56 -0500 Subject: [PATCH] Migrate swift from 4.0 to 4.2 --- .../DemoSwiftyCam.xcodeproj/project.pbxproj | 14 +++++++------ .../xcschemes/SwiftyCam-iOS.xcscheme | 4 +--- DemoSwiftyCam/DemoSwiftyCam/AppDelegate.swift | 2 +- .../DemoSwiftyCam/PhotoViewController.swift | 4 ++-- .../DemoSwiftyCam/VideoViewController.swift | 16 +++++++++++---- .../DemoSwiftyCam/ViewController.swift | 4 ++-- Source/Orientation.swift | 2 +- Source/SwiftyCamViewController.swift | 20 ++++++++++--------- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/project.pbxproj b/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/project.pbxproj index d020416..7872b96 100644 --- a/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/project.pbxproj +++ b/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/project.pbxproj @@ -179,7 +179,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0810; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = Cappsule; TargetAttributes = { 05D2A9B31E80BE9700B479E9 = { @@ -188,7 +188,7 @@ }; 1675A9711E00A68300B80903 = { CreatedOnToolsVersion = 8.1; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; ProvisioningStyle = Automatic; }; }; @@ -343,6 +343,7 @@ 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_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -350,6 +351,7 @@ 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; @@ -401,6 +403,7 @@ 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_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -408,6 +411,7 @@ 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; @@ -449,8 +453,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -465,8 +468,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.Walzy.DemoSwiftyCam1; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/xcshareddata/xcschemes/SwiftyCam-iOS.xcscheme b/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/xcshareddata/xcschemes/SwiftyCam-iOS.xcscheme index b6c9ea0..f1c1bc6 100644 --- a/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/xcshareddata/xcschemes/SwiftyCam-iOS.xcscheme +++ b/DemoSwiftyCam/DemoSwiftyCam.xcodeproj/xcshareddata/xcschemes/SwiftyCam-iOS.xcscheme @@ -1,6 +1,6 @@ @@ -37,7 +36,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/DemoSwiftyCam/DemoSwiftyCam/AppDelegate.swift b/DemoSwiftyCam/DemoSwiftyCam/AppDelegate.swift index dfee801..322b74d 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/AppDelegate.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/AppDelegate.swift @@ -22,7 +22,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 { // Override point for customization after application launch. return true } diff --git a/DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift index 4333a1f..1667af5 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/PhotoViewController.swift @@ -36,11 +36,11 @@ class PhotoViewController: UIViewController { super.viewDidLoad() self.view.backgroundColor = UIColor.gray let backgroundImageView = UIImageView(frame: view.frame) - backgroundImageView.contentMode = UIViewContentMode.scaleAspectFit + backgroundImageView.contentMode = UIView.ContentMode.scaleAspectFit backgroundImageView.image = backgroundImage view.addSubview(backgroundImageView) let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0)) - cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState()) + cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControl.State()) cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside) view.addSubview(cancelButton) } diff --git a/DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift index 0423a71..8121d1a 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/VideoViewController.swift @@ -49,20 +49,23 @@ class VideoViewController: UIViewController { playerController!.showsPlaybackControls = false playerController!.player = player! - self.addChildViewController(playerController!) + self.addChild(playerController!) self.view.addSubview(playerController!.view) playerController!.view.frame = view.frame NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidReachEnd), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.player!.currentItem) let cancelButton = UIButton(frame: CGRect(x: 10.0, y: 10.0, width: 30.0, height: 30.0)) - cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControlState()) + cancelButton.setImage(#imageLiteral(resourceName: "cancel"), for: UIControl.State()) cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside) view.addSubview(cancelButton) // Allow background audio to continue to play do { - try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient) + if #available(iOS 10.0, *) { + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient, mode: .default, options: []) + } else { + } } catch let error as NSError { print(error) } @@ -85,8 +88,13 @@ class VideoViewController: UIViewController { @objc fileprivate func playerItemDidReachEnd(_ notification: Notification) { if self.player != nil { - self.player!.seek(to: kCMTimeZero) + self.player!.seek(to: CMTime.zero) self.player!.play() } } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String { + return input.rawValue +} diff --git a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift index 67b2b8f..06a5d9b 100644 --- a/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift +++ b/DemoSwiftyCam/DemoSwiftyCam/ViewController.swift @@ -153,9 +153,9 @@ extension ViewController { fileprivate func toggleFlashAnimation() { if flashEnabled == true { - flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControlState()) + flashButton.setImage(#imageLiteral(resourceName: "flash"), for: UIControl.State()) } else { - flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControlState()) + flashButton.setImage(#imageLiteral(resourceName: "flashOutline"), for: UIControl.State()) } } } diff --git a/Source/Orientation.swift b/Source/Orientation.swift index f51030e..578d475 100644 --- a/Source/Orientation.swift +++ b/Source/Orientation.swift @@ -45,7 +45,7 @@ class Orientation { self.deviceOrientation = nil } - func getImageOrientation(forCamera: SwiftyCamViewController.CameraSelection) -> UIImageOrientation { + func getImageOrientation(forCamera: SwiftyCamViewController.CameraSelection) -> UIImage.Orientation { guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else { return forCamera == .rear ? .right : .leftMirrored } switch deviceOrientation { diff --git a/Source/SwiftyCamViewController.swift b/Source/SwiftyCamViewController.swift index bb48b20..b03ecc5 100644 --- a/Source/SwiftyCamViewController.swift +++ b/Source/SwiftyCamViewController.swift @@ -269,7 +269,7 @@ open class SwiftyCamViewController: UIViewController { super.viewDidLoad() previewLayer = PreviewView(frame: view.frame, videoGravity: videoGravity) view.addSubview(previewLayer) - view.sendSubview(toBack: previewLayer) + view.sendSubviewToBack(previewLayer) // Add Gesture Recognizers @@ -845,9 +845,9 @@ open class SwiftyCamViewController: UIViewController { alertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Alert OK button"), style: .cancel, handler: nil)) alertController.addAction(UIAlertAction(title: NSLocalizedString("Settings", comment: "Alert button to open Settings"), style: .default, handler: { action in if #available(iOS 10.0, *) { - UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!) + UIApplication.shared.openURL(URL(string: UIApplication.openSettingsURLString)!) } else { - if let appSettings = URL(string: UIApplicationOpenSettingsURLString) { + if let appSettings = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.openURL(appSettings) } } @@ -983,12 +983,14 @@ open class SwiftyCamViewController: UIViewController { do{ if #available(iOS 10.0, *) { - try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, - with: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP]) + try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowAirPlay, .allowBluetoothA2DP]) } else { - try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, - with: [.mixWithOthers, .allowBluetooth]) + let options: [AVAudioSession.CategoryOptions] = [.mixWithOthers, .allowBluetooth] + let category = AVAudioSession.Category.playAndRecord + let selector = NSSelectorFromString("setCategory:withOptions:error:") + AVAudioSession.sharedInstance().perform(selector, with: category, with: options) } + try AVAudioSession.sharedInstance().setActive(true) session.automaticallyConfiguresApplicationAudioSession = false } catch { @@ -1058,9 +1060,9 @@ extension SwiftyCamViewController : AVCaptureFileOutputRecordingDelegate { public func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) { if let currentBackgroundRecordingID = backgroundRecordingID { - backgroundRecordingID = UIBackgroundTaskInvalid + backgroundRecordingID = UIBackgroundTaskIdentifier.invalid - if currentBackgroundRecordingID != UIBackgroundTaskInvalid { + if currentBackgroundRecordingID != UIBackgroundTaskIdentifier.invalid { UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID) } }