From 39e191f5ed2b48fe10742f165a23614fa14672c5 Mon Sep 17 00:00:00 2001 From: Jeremy Arnold Date: Wed, 21 Aug 2019 19:34:12 -0700 Subject: [PATCH 1/2] Upgrade to Swift 5 --- .../project.pbxproj | 30 ++++++++++++--- .../DOAlertController-DEMO/AppDelegate.swift | 2 +- .../DOAlertController.swift | 38 +++++++++---------- .../ViewController.swift | 18 ++++----- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj index 7fae7d2..cffca91 100644 --- a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj +++ b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj @@ -169,7 +169,7 @@ attributes = { LastSwiftMigration = 0710; LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 1030; ORGANIZATIONNAME = "Daiki Okumura"; TargetAttributes = { 4F47CAAA1AE26BD100BF71E4 = { @@ -184,7 +184,7 @@ }; buildConfigurationList = 4F47CAA61AE26BD100BF71E4 /* Build configuration list for PBXProject "DOAlertController-DEMO" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -274,18 +274,27 @@ 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; 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; @@ -313,7 +322,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -321,18 +330,27 @@ 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; 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; @@ -352,7 +370,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -367,7 +385,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -382,7 +400,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift b/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift index 438052c..d56f471 100644 --- a/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMO/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/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift b/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift index e078ead..b08ceb9 100644 --- a/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift @@ -255,8 +255,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // NotificationCenter NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleAlertActionEnabledDidChangeNotification(_:)), name: NSNotification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) // Delegate self.transitioningDelegate = self @@ -304,7 +304,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // Screen Size var screenSize = presenting != nil ? presenting!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -534,8 +534,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont for button in buttons { let action = actions[button.tag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: buttonPositionX, y: buttonAreaPositionY, width: buttonWidth, height: buttonHeight) @@ -547,8 +547,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let action = actions[button.tag - 1] as! DOAlertAction if (action.style != DOAlertActionStyle.cancel) { button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -566,8 +566,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton let action = actions[cancelButtonTag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -599,7 +599,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont var screenSize = self.presentingViewController != nil ? self.presentingViewController!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -627,7 +627,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Button Tapped Action - func buttonTapped(_ sender: UIButton) { + @objc func buttonTapped(_ sender: UIButton) { sender.isSelected = true let action = actions[sender.tag - 1] as! DOAlertAction if (action.handler != nil) { @@ -637,7 +637,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Handle ContainerView tap gesture - func handleContainerViewTapGesture(_ sender: AnyObject) { + @objc func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { @@ -662,16 +662,16 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont @objc func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0.. Void = { - NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UITextFieldTextDidChange, object: alertController.textFields!.first) + let removeTextFieldObserver: () -> Void = { + NotificationCenter.default.removeObserver(self, name: UITextField.textDidChangeNotification, object: alertController.textFields!.first) } // Create the actions. let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Secure Text Entry\" alert's cancel action occured.") - removeTextFieldObserver() + removeTextFieldObserver() } let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Secure Text Entry\" alert's other action occured.") - removeTextFieldObserver() + removeTextFieldObserver() } // The text field initially has no text in the text field, so we'll disable it. @@ -242,7 +242,7 @@ class ViewController : UITableViewController, UITextFieldDelegate { label.text = "ID" label.font = UIFont(name: "GillSans-Bold", size: 15.0) textField?.leftView = label - textField?.leftViewMode = UITextFieldViewMode.always + textField?.leftViewMode = UITextField.ViewMode.always textField?.delegate = self } @@ -260,7 +260,7 @@ class ViewController : UITableViewController, UITextFieldDelegate { label.text = "PASS" label.font = UIFont(name: "GillSans-Bold", size: 15.0) textField?.leftView = label - textField?.leftViewMode = UITextFieldViewMode.always + textField?.leftViewMode = UITextField.ViewMode.always textField?.delegate = self } @@ -391,11 +391,11 @@ class ViewController : UITableViewController, UITextFieldDelegate { // MARK: UITextFieldTextDidChangeNotification - func handleTextFieldTextDidChangeNotification(_ notification: Notification) { + @objc func handleTextFieldTextDidChangeNotification(_ notification: Notification) { let textField = notification.object as! UITextField // Enforce a minimum length of >= 5 characters for secure text alerts. - secureTextAlertAction!.enabled = textField.text!.characters.count >= 5 + secureTextAlertAction!.enabled = textField.text!.count >= 5 } // MARK: UITextFieldDelegate Methods From d06583d03feaef9eac49242f5eec2b1e12ad66ac Mon Sep 17 00:00:00 2001 From: Jeremy Arnold Date: Wed, 21 Aug 2019 19:41:32 -0700 Subject: [PATCH 2/2] Upgrade to Swift 5 --- DOAlertController/DOAlertController.swift | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index e078ead..b08ceb9 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -255,8 +255,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // NotificationCenter NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleAlertActionEnabledDidChangeNotification(_:)), name: NSNotification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) // Delegate self.transitioningDelegate = self @@ -304,7 +304,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // Screen Size var screenSize = presenting != nil ? presenting!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -534,8 +534,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont for button in buttons { let action = actions[button.tag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: buttonPositionX, y: buttonAreaPositionY, width: buttonWidth, height: buttonHeight) @@ -547,8 +547,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let action = actions[button.tag - 1] as! DOAlertAction if (action.style != DOAlertActionStyle.cancel) { button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -566,8 +566,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton let action = actions[cancelButtonTag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: UIControl.State()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControl.State()) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -599,7 +599,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont var screenSize = self.presentingViewController != nil ? self.presentingViewController!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -627,7 +627,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Button Tapped Action - func buttonTapped(_ sender: UIButton) { + @objc func buttonTapped(_ sender: UIButton) { sender.isSelected = true let action = actions[sender.tag - 1] as! DOAlertAction if (action.handler != nil) { @@ -637,7 +637,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Handle ContainerView tap gesture - func handleContainerViewTapGesture(_ sender: AnyObject) { + @objc func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { @@ -662,16 +662,16 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont @objc func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0..