From b56c3aee9595564fc8b43160141afbc989c40d78 Mon Sep 17 00:00:00 2001 From: Bogdan Iusco <> Date: Fri, 22 Mar 2019 12:13:20 +0200 Subject: [PATCH] Migrated to Swift 4.2 --- .../project.pbxproj | 16 +++++++----- ScrollViewKeyboardResize/AppDelegate.swift | 2 +- UIViewController+Keyboard.swift | 26 +++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/ScrollViewKeyboardResize.xcodeproj/project.pbxproj b/ScrollViewKeyboardResize.xcodeproj/project.pbxproj index 88ccd4f..6070905 100644 --- a/ScrollViewKeyboardResize.xcodeproj/project.pbxproj +++ b/ScrollViewKeyboardResize.xcodeproj/project.pbxproj @@ -179,11 +179,11 @@ TargetAttributes = { EC687AFA1A8C938400BD1E6A = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1010; }; EC687B111A8C938400BD1E6A = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1010; TestTargetID = EC687AFA1A8C938400BD1E6A; }; }; @@ -378,7 +378,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "ScrollViewKeyboardResize/ScrollViewKeyboardResize-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -392,7 +393,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.haaakon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "ScrollViewKeyboardResize/ScrollViewKeyboardResize-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -412,7 +414,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.haaakon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScrollViewKeyboardResize.app/ScrollViewKeyboardResize"; }; name = Debug; @@ -429,7 +432,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "org.haaakon.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScrollViewKeyboardResize.app/ScrollViewKeyboardResize"; }; name = Release; diff --git a/ScrollViewKeyboardResize/AppDelegate.swift b/ScrollViewKeyboardResize/AppDelegate.swift index 397c1a0..24fe791 100644 --- a/ScrollViewKeyboardResize/AppDelegate.swift +++ b/ScrollViewKeyboardResize/AppDelegate.swift @@ -14,7 +14,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/UIViewController+Keyboard.swift b/UIViewController+Keyboard.swift index 1547b3f..0fe6dd4 100644 --- a/UIViewController+Keyboard.swift +++ b/UIViewController+Keyboard.swift @@ -12,14 +12,14 @@ private var scrollViewKey : UInt8 = 0 extension UIViewController { public func setupKeyboardNotifcationListenerForScrollView(_ scrollView: UIScrollView) { - NotificationCenter.default.addObserver(self, selector: #selector(UIViewController.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(UIViewController.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(UIViewController.keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(UIViewController.keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) internalScrollView = scrollView } public func removeKeyboardNotificationListeners() { - NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) - NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) } fileprivate var internalScrollView: UIScrollView! { @@ -33,25 +33,25 @@ extension UIViewController { @objc func keyboardWillShow(_ notification: Notification) { let userInfo = (notification as NSNotification).userInfo as! Dictionary - let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as! TimeInterval - let keyboardFrame = userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue + let animationDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! TimeInterval + let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey]?.cgRectValue let keyboardFrameConvertedToViewFrame = view.convert(keyboardFrame!, from: nil) - let options = UIViewAnimationOptions.beginFromCurrentState + let options = UIView.AnimationOptions.beginFromCurrentState UIView.animate(withDuration: animationDuration, delay: 0, options:options, animations: { () -> Void in let insetHeight = (self.internalScrollView.frame.height + self.internalScrollView.frame.origin.y) - keyboardFrameConvertedToViewFrame.origin.y - self.internalScrollView.contentInset = UIEdgeInsetsMake(0, 0, insetHeight, 0) - self.internalScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, insetHeight, 0) + self.internalScrollView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: insetHeight, right: 0) + self.internalScrollView.scrollIndicatorInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: insetHeight, right: 0) }) { (complete) -> Void in } } @objc func keyboardWillHide(_ notification: Notification) { let userInfo = (notification as NSNotification).userInfo as! Dictionary - let animationDuration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as! TimeInterval - let options = UIViewAnimationOptions.beginFromCurrentState + let animationDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! TimeInterval + let options = UIView.AnimationOptions.beginFromCurrentState UIView.animate(withDuration: animationDuration, delay: 0, options:options, animations: { () -> Void in - self.internalScrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) - self.internalScrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0) + self.internalScrollView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0) + self.internalScrollView.scrollIndicatorInsets = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0) }) { (complete) -> Void in } }