diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index a76861f7..6fd2f274 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -181,12 +181,12 @@ TargetAttributes = { D2515E6E1BC1A47F00ED606F = { CreatedOnToolsVersion = 7.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; ProvisioningStyle = Manual; }; D2C0AFCC1BE7236A00F31D0F = { CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; ProvisioningStyle = Manual; TestTargetID = D2515E6E1BC1A47F00ED606F; }; @@ -390,7 +390,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -408,7 +408,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ScottyDoesntCode.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -422,7 +422,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ScottyDoesntCode.SDCAlertView-UI-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; @@ -437,7 +437,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ScottyDoesntCode.SDCAlertView-UI-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TEST_TARGET_NAME = Example; USES_XCTRUNNER = YES; }; diff --git a/Example/DemoViewController.swift b/Example/DemoViewController.swift index 6e3a9fae..080379d8 100644 --- a/Example/DemoViewController.swift +++ b/Example/DemoViewController.swift @@ -53,7 +53,7 @@ final class DemoViewController: UITableViewController { switch self.contentControl.selectedSegmentIndex { case 1: let contentView = alert.contentView - let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray) + let spinner = UIActivityIndicatorView(style: .gray) spinner.translatesAutoresizingMaskIntoConstraints = false spinner.startAnimating() contentView.addSubview(spinner) @@ -105,7 +105,7 @@ final class DemoViewController: UITableViewController { private func presentUIAlertController() { let title = self.titleTextField.content let message = self.messageTextField.content - let style = UIAlertControllerStyle(rawValue: self.styleControl.selectedSegmentIndex)! + let style = UIAlertController.Style(rawValue: self.styleControl.selectedSegmentIndex)! let alert = UIAlertController(title: title, message: message, preferredStyle: style) let textFields = Int(self.textFieldCountTextField.content ?? "0")! diff --git a/Example/TestsViewController.swift b/Example/TestsViewController.swift index 0acd41f5..60f4bc80 100644 --- a/Example/TestsViewController.swift +++ b/Example/TestsViewController.swift @@ -55,7 +55,7 @@ class TestsViewController: UITableViewController { case 8: let alert = AlertController(title: "Title", message: "Message") let contentView = alert.contentView - let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray) + let spinner = UIActivityIndicatorView(style: .gray) spinner.translatesAutoresizingMaskIntoConstraints = false spinner.startAnimating() contentView.addSubview(spinner) @@ -81,7 +81,7 @@ class TestsViewController: UITableViewController { case 11: let alert = AlertController(title: "Title", message: "Message", preferredStyle: .actionSheet) let contentView = alert.contentView - let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray) + let spinner = UIActivityIndicatorView(style: .gray) spinner.translatesAutoresizingMaskIntoConstraints = false spinner.startAnimating() contentView.addSubview(spinner) diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 381ab841..e8b13841 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -210,7 +210,7 @@ TargetAttributes = { D2515EC01BC1A7D500ED606F = { CreatedOnToolsVersion = 7.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; ProvisioningStyle = Manual; }; }; @@ -302,7 +302,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -332,7 +332,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.ScottyDoesntCode.SDCAlertView; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Source/Actions/AlertAction.swift b/Source/Actions/AlertAction.swift index 36577732..cc33af98 100644 --- a/Source/Actions/AlertAction.swift +++ b/Source/Actions/AlertAction.swift @@ -1,31 +1,14 @@ import UIKit -/** -The action's style - -- normal: The action will have default font and text color -- preferred: The action will take a style that indicates it's the preferred option -- destructive: The action will convey that this action will do something destructive -*/ -@objc(SDCAlertActionStyle) -public enum AlertActionStyle: Int { - case normal - case preferred - case destructive -} - @objc(SDCAlertAction) public class AlertAction: NSObject { - - /** - Creates an action with a plain title. - - - parameter title: An optional title for the action - - parameter style: The action's style - - parameter handler: An optional closure that's called when the user taps on this action - */ + /// Creates an action with a plain title. + /// + /// parameter title: An optional title for the action + /// parameter style: The action's style + /// parameter handler: An optional closure that's called when the user taps on this action @objc - public convenience init(title: String?, style: AlertActionStyle, handler: ((AlertAction) -> Void)? = nil) + public convenience init(title: String?, style: AlertAction.Style, handler: ((AlertAction) -> Void)? = nil) { self.init() self.title = title @@ -33,15 +16,13 @@ public class AlertAction: NSObject { self.handler = handler } - /** - Creates an action with a stylized title. - - - parameter attributedTitle: An optional stylized title - - parameter style: The action's style - - parameter handler: An optional closure that is called when the user taps on this action - */ @objc - public convenience init(attributedTitle: NSAttributedString?, style: AlertActionStyle, + /// Creates an action with a stylized title. + /// + /// - parameter attributedTitle: An optional stylized title + /// - parameter style: The action's style + /// - parameter handler: An optional closure that is called when the user taps on this action + public convenience init(attributedTitle: NSAttributedString?, style: AlertAction.Style, handler: ((AlertAction) -> Void)? = nil) { self.init() @@ -67,7 +48,7 @@ public class AlertAction: NSObject { /// The action's style. @objc - internal(set) public var style: AlertActionStyle = .normal + internal(set) public var style: AlertAction.Style = .normal /// The action's button accessibility identifier @objc @@ -83,3 +64,16 @@ public class AlertAction: NSObject { didSet { self.actionView?.isEnabled = self.isEnabled } } } + +extension AlertAction { + /// The action's style + @objc(SDCAlertActionStyle) + public enum Style: Int { + /// The action will have default font and text color + case normal + /// The action will take a style that indicates it's the preferred option + case preferred + /// The action will convey that this action will do something destructive + case destructive + } +} diff --git a/Source/AlertController.swift b/Source/AlertController.swift index 6a62e45e..af78efc5 100644 --- a/Source/AlertController.swift +++ b/Source/AlertController.swift @@ -1,27 +1,23 @@ import UIKit /// The alert controller's style -/// -/// - actionSheet: An action sheet style alert that slides in from the bottom and presents the user with a -/// list of possible actions to perform. Does not show as expected on iPad. -/// - alert: The standard alert style that asks the user for information or confirmation. @objc(SDCAlertControllerStyle) public enum AlertControllerStyle: Int { + // An action sheet style alert that slides in from the bottom and presents the user with a list of + // possible actions to perform. Does not show as expected on iPad. case actionSheet + // The standard alert style that asks the user for information or confirmation. case alert } - -/// The layout of the alert's actions. Only applies to AlertControllerStyle.alert, not .actionSheet (see -/// `AlertControllerStyle`). -/// -/// - automatic: If the alert has 2 actions, display them horizontally. Otherwise, display them vertically. -/// - vertical: Display the actions vertically. -/// - horizontal: Display the actions horizontally. +/// The layout of the alert's actions. Only applies to AlertControllerStyle.alert, not .actionSheet. @objc(SDCActionLayout) public enum ActionLayout: Int { + /// If the alert has 2 actions, display them horizontally. Otherwise, display them vertically. case automatic + /// Display the actions vertically. case vertical + /// Display the actions horizontally. case horizontal } @@ -96,7 +92,7 @@ public final class AlertController: UIViewController { } } - /// The layout of the actions in the alert. + /// The layout of the actions in the alert, or `.automatic` for action sheets. @objc public var actionLayout: ActionLayout { get { return (self.alert as? AlertView)?.actionLayout ?? .automatic } @@ -114,7 +110,7 @@ public final class AlertController: UIViewController { /// on an action. If it returns false, the AlertAction handler will not be executed. @objc public var shouldDismissHandler: ((AlertAction?) -> Bool)? - + /// A closure called when the alert is dismissed after an outside tap (when `dismissOnOutsideTap` behavior /// is enabled) @objc @@ -126,7 +122,7 @@ public final class AlertController: UIViewController { /// The alert's presentation style. @objc - private(set) public var preferredStyle: AlertControllerStyle = .alert + public let preferredStyle: AlertControllerStyle private let alert: UIView & AlertControllerViewRepresentable private lazy var transitionDelegate: Transition = Transition(alertStyle: self.preferredStyle) @@ -145,7 +141,6 @@ public final class AlertController: UIViewController { preferredStyle: AlertControllerStyle = .alert) { self.init(preferredStyle: preferredStyle) - self.preferredStyle = preferredStyle self.commonInit() self.attributedTitle = attributedTitle @@ -159,9 +154,9 @@ public final class AlertController: UIViewController { /// - parameter message: An optional message /// - parameter preferredStyle: The preferred presentation style of the alert. Default is `alert`. @objc - public convenience init(title: String?, message: String?, preferredStyle: AlertControllerStyle = .alert) { + public convenience init(title: String?, message: String?, preferredStyle: AlertControllerStyle = .alert) + { self.init(preferredStyle: preferredStyle) - self.preferredStyle = preferredStyle self.commonInit() self.title = title @@ -183,6 +178,7 @@ public final class AlertController: UIViewController { } } + self.preferredStyle = preferredStyle super.init(nibName: nil, bundle: nil) } @@ -259,12 +255,21 @@ public final class AlertController: UIViewController { self.textFields?.first?.resignFirstResponder() } + public override func becomeFirstResponder() -> Bool { + if self.behaviors.contains(.automaticallyFocusTextField) { + return self.textFields?.first?.becomeFirstResponder() ?? super.becomeFirstResponder() + } + + return super.becomeFirstResponder() + } + public override var preferredStatusBarStyle: UIStatusBarStyle { return self.presentingViewController?.preferredStatusBarStyle ?? .default } public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { - return self.presentingViewController?.supportedInterfaceOrientations ?? super.supportedInterfaceOrientations + return self.presentingViewController?.supportedInterfaceOrientations + ?? super.supportedInterfaceOrientations } // MARK: - Private @@ -277,13 +282,14 @@ public final class AlertController: UIViewController { } private func listenForKeyboardChanges() { - NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardChange), - name: .UIKeyboardWillChangeFrame, object: nil) + NotificationCenter.default + .addObserver(self, selector: #selector(self.keyboardChange), + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) } @objc private func keyboardChange(_ notification: Notification) { - let newFrameValue = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue + let newFrameValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue guard let newFrame = newFrameValue?.cgRectValue else { return } @@ -292,14 +298,6 @@ public final class AlertController: UIViewController { self.alert.layoutIfNeeded() } - public override func becomeFirstResponder() -> Bool { - if self.behaviors.contains(.automaticallyFocusTextField) { - return self.textFields?.first?.becomeFirstResponder() ?? super.becomeFirstResponder() - } - - return super.becomeFirstResponder() - } - private func configureAlertView() { self.alert.translatesAutoresizingMaskIntoConstraints = false self.alert.visualStyle = self.visualStyle @@ -362,10 +360,10 @@ public final class AlertController: UIViewController { } let textFieldsViewController = TextFieldsViewController(textFields: textFields) - textFieldsViewController.willMove(toParentViewController: self) - self.addChildViewController(textFieldsViewController) + textFieldsViewController.willMove(toParent: self) + self.addChild(textFieldsViewController) alert.textFieldsViewController = textFieldsViewController - textFieldsViewController.didMove(toParentViewController: self) + textFieldsViewController.didMove(toParent: self) } private func addChromeTapHandlerIfNecessary() { diff --git a/Source/AlertVisualStyle.swift b/Source/AlertVisualStyle.swift index 639deee6..52cf9cae 100644 --- a/Source/AlertVisualStyle.swift +++ b/Source/AlertVisualStyle.swift @@ -99,7 +99,7 @@ open class AlertVisualStyle: NSObject { switch alertStyle { case .alert: if kIsIphoneX { - self.margins = .zero + self.margins = UIEdgeInsets() } else { self.margins = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0) } diff --git a/Source/Text Fields/TextFieldCell.swift b/Source/Text Fields/TextFieldCell.swift index 07fff27a..279e3af9 100644 --- a/Source/Text Fields/TextFieldCell.swift +++ b/Source/Text Fields/TextFieldCell.swift @@ -38,7 +38,7 @@ final class TextFieldCell: UITableViewCell { container?.addSubview(textField) textField.translatesAutoresizingMaskIntoConstraints = false - let insets = self.visualStyle?.textFieldMargins ?? UIEdgeInsets.zero + let insets = self.visualStyle?.textFieldMargins ?? UIEdgeInsets() let leading = textField.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: insets.left) let trailing = textField.trailingAnchor.constraint(equalTo: self.trailingAnchor, diff --git a/Source/Views/ActionSheetView.swift b/Source/Views/ActionSheetView.swift index 9e2220fb..79e2bf0d 100644 --- a/Source/Views/ActionSheetView.swift +++ b/Source/Views/ActionSheetView.swift @@ -55,7 +55,7 @@ final class ActionSheetView: UIView, AlertControllerViewRepresentable { self.cancelButton.isHighlighted = cancelIsSelected if cancelIsSelected && sender.state == .ended { - self.cancelButton.sendActions(for: .touchUpInside) + self.cancelButton.sendActions(for: UIControl.Event.touchUpInside) } } diff --git a/Source/Views/AlertView.swift b/Source/Views/AlertView.swift index c6fdcdc3..d0e8ffc3 100644 --- a/Source/Views/AlertView.swift +++ b/Source/Views/AlertView.swift @@ -121,7 +121,7 @@ final class AlertView: UIView, AlertControllerViewRepresentable { override var intrinsicContentSize: CGSize { let totalHeight = self.contentHeight + self.actionsCollectionView.displayHeight - return CGSize(width: UIViewNoIntrinsicMetric, height: totalHeight) + return CGSize(width: UIView.noIntrinsicMetric, height: totalHeight) } @objc diff --git a/Source/Views/UIView+Accessibility.swift b/Source/Views/UIView+Accessibility.swift index 96d6f858..59e6c1e0 100644 --- a/Source/Views/UIView+Accessibility.swift +++ b/Source/Views/UIView+Accessibility.swift @@ -3,7 +3,7 @@ import UIKit extension UIView { func setupAccessibility(using action: AlertAction) { self.accessibilityLabel = action.attributedTitle?.string - self.accessibilityTraits = UIAccessibilityTraitButton + self.accessibilityTraits = .button self.accessibilityIdentifier = action.accessibilityIdentifier self.isAccessibilityElement = true }