From b23968adec930bcd9eea09dbf91850fa59ce8122 Mon Sep 17 00:00:00 2001 From: eyupodeal Date: Thu, 29 Mar 2018 15:03:25 +0300 Subject: [PATCH] Swift-4 Convert --- .../project.pbxproj | 22 ++++++++++++++++- .../AppDelegate.swift | 24 +++++++++---------- .../PresentedViewController.swift | 11 +++++---- .../ViewController.swift | 13 +++++----- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/DeviceRotationOnlyOneViewController.xcodeproj/project.pbxproj b/DeviceRotationOnlyOneViewController.xcodeproj/project.pbxproj index ff3d134..38e64fc 100644 --- a/DeviceRotationOnlyOneViewController.xcodeproj/project.pbxproj +++ b/DeviceRotationOnlyOneViewController.xcodeproj/project.pbxproj @@ -94,7 +94,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = jairobjunior; TargetAttributes = { 1DFC39361C8C190200D80572 = { @@ -174,13 +174,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -218,13 +226,21 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -243,6 +259,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -255,6 +272,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.jairobjunior.DeviceRotationOnlyOneViewController; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -266,6 +284,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.jairobjunior.DeviceRotationOnlyOneViewController; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -288,6 +307,7 @@ 1DFC394B1C8C190200D80572 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/DeviceRotationOnlyOneViewController/AppDelegate.swift b/DeviceRotationOnlyOneViewController/AppDelegate.swift index 6dd6aae..621c81c 100644 --- a/DeviceRotationOnlyOneViewController/AppDelegate.swift +++ b/DeviceRotationOnlyOneViewController/AppDelegate.swift @@ -40,27 +40,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } - - func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask { - if let rootViewController = self.topViewControllerWithRootViewController(window?.rootViewController) { - if (rootViewController.respondsToSelector(Selector("canRotate"))) { + + func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { + if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) { + if (rootViewController.responds(to: Selector(("canRotate")))) { // .respondsToSelector(Selector("canRotate"))) { // Unlock landscape view orientations for this view controller - return .AllButUpsideDown; + return .allButUpsideDown; } } // Only allow portrait (standard behaviour) - return .Portrait; + return .portrait; } - + private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? { if (rootViewController == nil) { return nil } - if (rootViewController.isKindOfClass(UITabBarController)) { - return topViewControllerWithRootViewController((rootViewController as! UITabBarController).selectedViewController) - } else if (rootViewController.isKindOfClass(UINavigationController)) { - return topViewControllerWithRootViewController((rootViewController as! UINavigationController).visibleViewController) + if (rootViewController.isKind(of:UITabBarController.self)) { + return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController) + } else if (rootViewController.isKind(of:UINavigationController.self)) { + return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController) } else if (rootViewController.presentedViewController != nil) { - return topViewControllerWithRootViewController(rootViewController.presentedViewController) + return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController) } return rootViewController } diff --git a/DeviceRotationOnlyOneViewController/PresentedViewController.swift b/DeviceRotationOnlyOneViewController/PresentedViewController.swift index b7c5092..95619ed 100644 --- a/DeviceRotationOnlyOneViewController/PresentedViewController.swift +++ b/DeviceRotationOnlyOneViewController/PresentedViewController.swift @@ -9,17 +9,18 @@ import UIKit class PresentedViewController: UIViewController { - + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } - + @IBAction func didDismissButtonPress(sender: UIButton) { - self.dismissViewControllerAnimated(true) { () -> Void in - UIDevice.currentDevice().setValue(Int(UIInterfaceOrientation.Portrait.rawValue), forKey: "orientation") + self.dismiss(animated: true) { () -> Void in + UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation") } } - + func canRotate() -> Void {} } + diff --git a/DeviceRotationOnlyOneViewController/ViewController.swift b/DeviceRotationOnlyOneViewController/ViewController.swift index 0a7276a..283baf9 100644 --- a/DeviceRotationOnlyOneViewController/ViewController.swift +++ b/DeviceRotationOnlyOneViewController/ViewController.swift @@ -14,14 +14,15 @@ class ViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } - - override func viewWillDisappear(animated : Bool) { + + override func viewWillDisappear(_ animated : Bool) { super.viewWillDisappear(animated) - - if (self.isMovingFromParentViewController()) { - UIDevice.currentDevice().setValue(Int(UIInterfaceOrientation.Portrait.rawValue), forKey: "orientation") + + if (self.isMovingFromParentViewController) { + UIDevice.current.setValue(Int(UIInterfaceOrientation.portrait.rawValue), forKey: "orientation") } } - + func canRotate() -> Void {} } +