diff --git a/catalog/BUILD b/catalog/BUILD index 1fdd8967420..9a334733811 100644 --- a/catalog/BUILD +++ b/catalog/BUILD @@ -66,7 +66,7 @@ swift_library( srcs = native.glob(["MDCCatalog/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], resources = ["MDCDragons/HeaderView.xib"], deps = [ @@ -120,7 +120,7 @@ swift_library( srcs = native.glob(["MDCDragons/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], data = glob(["MDCCatalog/Assets.xcassets/*.imageset/**"]), resources = ["MDCDragons/HeaderView.xib"], diff --git a/catalog/MDCCatalog.xcodeproj/project.pbxproj b/catalog/MDCCatalog.xcodeproj/project.pbxproj index 91feaeb9c10..f0e8804d50f 100644 --- a/catalog/MDCCatalog.xcodeproj/project.pbxproj +++ b/catalog/MDCCatalog.xcodeproj/project.pbxproj @@ -593,7 +593,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.mdc-catalog.MDCActionExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -613,7 +613,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.mdc-catalog.MDCActionExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -738,7 +738,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "MDCCatalog/MDCCatalog-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -756,7 +756,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.google.MDCCatalog; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "MDCCatalog/MDCCatalog-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/catalog/MDCCatalog/AppDelegate.swift b/catalog/MDCCatalog/AppDelegate.swift index 57b5fce3fdb..107dc1c966a 100644 --- a/catalog/MDCCatalog/AppDelegate.swift +++ b/catalog/MDCCatalog/AppDelegate.swift @@ -32,7 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MDCAppBarNavigationContro let navigationController = MDCAppBarNavigationController() func application(_ application: UIApplication, didFinishLaunchingWithOptions - launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { self.window = MDCCatalogWindow(frame: UIScreen.main.bounds) // The navigation tree will only take examples that implement @@ -66,9 +66,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MDCAppBarNavigationContro return true } - func themeDidChange(notification: NSNotification) { + @objc func themeDidChange(notification: NSNotification) { let colorScheme = AppTheme.globalTheme.colorScheme - for viewController in navigationController.childViewControllers { + for viewController in navigationController.children { guard let appBar = navigationController.appBar(for: viewController) else { continue } @@ -104,7 +104,7 @@ protocol CatalogAppBarInjectee { } extension UINavigationController { - func presentMenu() { + @objc func presentMenu() { let menuViewController = MDCMenuViewController(style: .plain) let bottomSheet = MDCBottomSheetController(contentViewController: menuViewController) self.present(bottomSheet, animated: true, completion: nil) diff --git a/catalog/MDCCatalog/MDCCatalogCollectionViewCell.swift b/catalog/MDCCatalog/MDCCatalogCollectionViewCell.swift index 380627545a2..ecf462b5727 100644 --- a/catalog/MDCCatalog/MDCCatalogCollectionViewCell.swift +++ b/catalog/MDCCatalog/MDCCatalogCollectionViewCell.swift @@ -38,7 +38,9 @@ class MDCCatalogCollectionViewCell: UICollectionViewCell { contentView.clipsToBounds = true contentView.addSubview(tile) self.isAccessibilityElement = true - self.accessibilityTraits |= UIAccessibilityTraitButton + let rawAccessibilityTraits = + accessibilityTraits.rawValue | UIAccessibilityTraits.button.rawValue + self.accessibilityTraits = UIAccessibilityTraits(rawValue: rawAccessibilityTraits) updateTheme() @@ -85,7 +87,7 @@ class MDCCatalogCollectionViewCell: UICollectionViewCell { label.textColor = AppTheme.globalTheme.colorScheme.onBackgroundColor } - func themeDidChange(notification: NSNotification) { + @objc func themeDidChange(notification: NSNotification) { updateTheme() } diff --git a/catalog/MDCCatalog/MDCCatalogComponentsController.swift b/catalog/MDCCatalog/MDCCatalogComponentsController.swift index 534a336426c..f3c14367476 100644 --- a/catalog/MDCCatalog/MDCCatalogComponentsController.swift +++ b/catalog/MDCCatalog/MDCCatalogComponentsController.swift @@ -27,7 +27,7 @@ import MaterialComponents.MaterialTypography import UIKit -class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchControllerDelegate { +class MDCCatalogComponentsController: UICollectionViewController, UICollectionViewDelegateFlowLayout, MDCInkTouchControllerDelegate { fileprivate struct Constants { static let headerScrollThreshold: CGFloat = 30 @@ -94,7 +94,7 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon title = "Material Components for iOS" - addChildViewController(headerViewController) + addChild(headerViewController) headerViewController.isTopLayoutGuideAdjustmentEnabled = true headerViewController.inferTopSafeAreaInsetFromViewController = true @@ -115,7 +115,7 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon object: nil) } - func themeDidChange(notification: NSNotification) { + @objc func themeDidChange(notification: NSNotification) { let colorScheme = AppTheme.globalTheme.colorScheme MDCFlexibleHeaderColorThemer.applySemanticColorScheme(colorScheme, to: headerViewController.headerView) @@ -198,18 +198,12 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon } view.addSubview(headerViewController.view) - #if swift(>=4.2) headerViewController.didMove(toParent: self) - #else - headerViewController.didMove(toParentViewController: self) - #endif collectionView?.accessibilityIdentifier = "collectionView" -#if swift(>=3.2) if #available(iOS 11.0, *) { collectionView?.contentInsetAdjustmentBehavior = .always } -#endif } override func viewWillAppear(_ animated: Bool) { @@ -223,15 +217,14 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon collectionView?.collectionViewLayout.invalidateLayout() } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return headerViewController } - override var childViewControllerForStatusBarHidden: UIViewController? { + override var childForStatusBarHidden: UIViewController? { return headerViewController } -#if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { // Re-constraint the title label to account for changes in safeAreaInsets's left and right. @@ -239,7 +232,6 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon menuButtonRightPaddingConstraint?.constant = -1 * (Constants.inset + view.safeAreaInsets.right) menuTopPaddingConstraint?.constant = Constants.inset + view.safeAreaInsets.top } -#endif func setupFlexibleHeaderContentConstraints() { @@ -364,14 +356,12 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, - sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize { + sizeForItemAt indexPath: IndexPath) -> CGSize { let dividerWidth: CGFloat = 1 var safeInsets: CGFloat = 0 -#if swift(>=3.2) if #available(iOS 11, *) { safeInsets = view.safeAreaInsets.left + view.safeAreaInsets.right } -#endif var cellWidthHeight: CGFloat // iPhones have 2 columns in portrait and 3 in landscape diff --git a/catalog/MDCCatalog/MDCCatalogDebugAlert.swift b/catalog/MDCCatalog/MDCCatalogDebugAlert.swift index b891ea8bb1e..2fc0fd08a4c 100644 --- a/catalog/MDCCatalog/MDCCatalogDebugAlert.swift +++ b/catalog/MDCCatalog/MDCCatalogDebugAlert.swift @@ -195,7 +195,7 @@ class MDCCatalogDebugDismissCell: UICollectionViewCell { label.text = "DISMISS" label.textAlignment = .center isAccessibilityElement = true - accessibilityTraits = UIAccessibilityTraitButton + accessibilityTraits = .button accessibilityLabel = label.text contentView.addSubview(label) } diff --git a/catalog/MDCCatalog/MDCCatalogTileView.swift b/catalog/MDCCatalog/MDCCatalogTileView.swift index 307649423e1..735884344bd 100644 --- a/catalog/MDCCatalog/MDCCatalogTileView.swift +++ b/catalog/MDCCatalog/MDCCatalogTileView.swift @@ -54,7 +54,7 @@ class MDCCatalogTileView: UIView { super.init(coder: aDecoder) } - func themeDidChange(notification: NSNotification) { + @objc func themeDidChange(notification: NSNotification) { imageCache.removeAllObjects() } diff --git a/catalog/MDCCatalog/MDCDebugSafeAreaInsetsView.swift b/catalog/MDCCatalog/MDCDebugSafeAreaInsetsView.swift index 327bff08f1d..ace6f67ff11 100644 --- a/catalog/MDCCatalog/MDCDebugSafeAreaInsetsView.swift +++ b/catalog/MDCCatalog/MDCDebugSafeAreaInsetsView.swift @@ -37,20 +37,16 @@ class MDCDebugSafeAreaInsetsView: UIView { fatalError("init(coder:) has not been implemented") } -#if swift(>=3.2) override open func safeAreaInsetsDidChange() { setNeedsLayout() layoutIfNeeded() } -#endif override func layoutSubviews() { var safeAreaInsets = UIEdgeInsets.zero -#if swift(>=3.2) if #available(iOS 11, *) { safeAreaInsets = self.safeAreaInsets } -#endif let width = frame.width let height = frame.height diff --git a/catalog/MDCCatalog/MDCNodeListViewController.swift b/catalog/MDCCatalog/MDCNodeListViewController.swift index 0ecdc992ac9..b3864c4884c 100644 --- a/catalog/MDCCatalog/MDCNodeListViewController.swift +++ b/catalog/MDCCatalog/MDCNodeListViewController.swift @@ -30,7 +30,7 @@ class NodeViewTableViewDemoCell: UITableViewCell { let label = UILabel() - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) textLabel!.font = MDCTypography.subheadFont() imageView!.image = UIImage(named: "Demo") @@ -95,7 +95,7 @@ class NodeViewTableViewPrimaryDemoCell: UITableViewCell { let containedButton = MDCButton() - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) setupContainedButton() } @@ -213,14 +213,10 @@ class MDCNodeListViewController: CBCNodeListViewController { additionalExamplesSectionHeader = createAdditionalExamplesSectionHeader() self.tableView.backgroundColor = UIColor.white self.tableView.separatorStyle = .none - self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension + self.tableView.sectionHeaderHeight = UITableView.automaticDimension var charactersCount = 0 - #if swift(>=3.2) - charactersCount = node.title.count - #else - charactersCount = node.title.characters.count - #endif + charactersCount = node.title.count if charactersCount > 0 { self.tableView.accessibilityIdentifier = "Table" + node.title } else { @@ -239,7 +235,7 @@ class MDCNodeListViewController: CBCNodeListViewController { self.navigationController?.setNavigationBarHidden(true, animated: animated) } - func themeDidChange(notification: NSNotification) { + @objc func themeDidChange(notification: NSNotification) { setNeedsStatusBarAppearanceUpdate() self.tableView.reloadData() } @@ -298,7 +294,7 @@ extension MDCNodeListViewController { sectionTitleLabel.translatesAutoresizingMaskIntoConstraints = false sectionTitleLabel.text = sectionNames[1] sectionTitleLabel.numberOfLines = 0 - sectionTitleLabel.setContentCompressionResistancePriority(1000, for: .vertical) + sectionTitleLabel.setContentCompressionResistancePriority(.required, for: .vertical) sectionView.addSubview(lineDivider) sectionView.addSubview(sectionTitleLabel) @@ -368,7 +364,6 @@ extension MDCNodeListViewController { constant: self.padding).isActive = true } // Title Label to Section View - #if swift(>=3.2) if #available(iOS 11.0, *) { // Align to the safe area insets. sectionTitleLabel.leadingAnchor @@ -380,9 +375,6 @@ extension MDCNodeListViewController { } else { preiOS11Behavior() } - #else - preiOS11Behavior() - #endif NSLayoutConstraint( item: sectionView, @@ -405,7 +397,7 @@ extension MDCNodeListViewController { sectionTitleLabel.translatesAutoresizingMaskIntoConstraints = false sectionTitleLabel.text = sectionNames[0] sectionTitleLabel.numberOfLines = 0 - sectionTitleLabel.setContentCompressionResistancePriority(1000, for: .vertical) + sectionTitleLabel.setContentCompressionResistancePriority(.required, for: .vertical) mainSectionHeaderTitleLabel = sectionTitleLabel let descriptionLabel = UILabel() @@ -413,14 +405,14 @@ extension MDCNodeListViewController { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = descriptionLineHeight - descriptionLabel.font.lineHeight - let attrs = [NSParagraphStyleAttributeName: paragraphStyle] + let attrs = [NSAttributedString.Key.paragraphStyle: paragraphStyle] descriptionLabel.attributedText = NSAttributedString(string:componentDescription, attributes:attrs) descriptionLabel.alpha = MDCTypography.body1FontOpacity() descriptionLabel.translatesAutoresizingMaskIntoConstraints = false descriptionLabel.numberOfLines = 0 - descriptionLabel.setContentCompressionResistancePriority(1000, for: .vertical) + descriptionLabel.setContentCompressionResistancePriority(.required, for: .vertical) mainSectionHeaderDescriptionLabel = descriptionLabel sectionView.addSubview(sectionTitleLabel) @@ -445,7 +437,6 @@ extension MDCNodeListViewController { multiplier: 1.0, constant: self.padding).isActive = true } - #if swift(>=3.2) if #available(iOS 11.0, *) { // Align to the safe area insets. sectionTitleLabel.leadingAnchor @@ -457,9 +448,6 @@ extension MDCNodeListViewController { } else { preiOS11Behavior() } - #else - preiOS11Behavior() - #endif NSLayoutConstraint( item: sectionTitleLabel, @@ -555,7 +543,7 @@ extension MDCNodeListViewController { return true } - func primaryDemoButtonClicked () { + @objc func primaryDemoButtonClicked () { let indexPath = IndexPath(row: 0, section: Section.description.rawValue) self.tableView(self.tableView, didSelectRowAt: indexPath) } diff --git a/catalog/MDCDragons.xcodeproj/project.pbxproj b/catalog/MDCDragons.xcodeproj/project.pbxproj index f8e4b5b4d31..69d5e94e86f 100644 --- a/catalog/MDCDragons.xcodeproj/project.pbxproj +++ b/catalog/MDCDragons.xcodeproj/project.pbxproj @@ -376,7 +376,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.google.MDCDragons; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -392,7 +392,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.google.MDCDragons; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/catalog/MDCDragons/AppDelegate.swift b/catalog/MDCDragons/AppDelegate.swift index 0991ba9d623..d3388ad5d53 100644 --- a/catalog/MDCDragons/AppDelegate.swift +++ b/catalog/MDCDragons/AppDelegate.swift @@ -21,7 +21,7 @@ import CatalogByConvention 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 { self.window = UIWindow(frame: UIScreen.main.bounds) UIApplication.shared.statusBarStyle = .lightContent let tree = CBCCreateNavigationTree() diff --git a/catalog/MDCDragons/MDCDragonsController.swift b/catalog/MDCDragons/MDCDragonsController.swift index 335ac64c584..22c185fe71d 100644 --- a/catalog/MDCDragons/MDCDragonsController.swift +++ b/catalog/MDCDragons/MDCDragonsController.swift @@ -92,7 +92,7 @@ class MDCDragonsController: UIViewController, override func viewDidLoad() { super.viewDidLoad() title = "Material Dragons" - addChildViewController(headerViewController) + addChild(headerViewController) headerViewController.headerView.minMaxHeightIncludesSafeArea = false headerViewController.headerView.maximumHeight = Constants.headerViewMaxHeight headerViewController.headerView.minimumHeight = Constants.headerViewMinHeight @@ -105,32 +105,26 @@ class MDCDragonsController: UIViewController, view.addSubview(tableView) view.backgroundColor = Constants.bgColor - #if swift(>=3.2) - if #available(iOS 11, *) { - tableView.translatesAutoresizingMaskIntoConstraints = false + if #available(iOS 11, *) { + tableView.translatesAutoresizingMaskIntoConstraints = false - let guide = view.safeAreaLayoutGuide - NSLayoutConstraint.activate([tableView.leftAnchor.constraint(equalTo: guide.leftAnchor), - tableView.rightAnchor.constraint(equalTo: guide.rightAnchor), - tableView.topAnchor.constraint(equalTo: view.topAnchor), - tableView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) - } else { - preiOS11Constraints() - } - #else + let guide = view.safeAreaLayoutGuide + NSLayoutConstraint.activate([tableView.leftAnchor.constraint(equalTo: guide.leftAnchor), + tableView.rightAnchor.constraint(equalTo: guide.rightAnchor), + tableView.topAnchor.constraint(equalTo: view.topAnchor), + tableView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) + } else { preiOS11Constraints() - #endif + } setupHeaderView() let tapgesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) tapgesture.delegate = self view.addGestureRecognizer(tapgesture) - #if swift(>=3.2) - if #available(iOS 11.0, *) { - tableView.contentInsetAdjustmentBehavior = .always - } - #endif + if #available(iOS 11.0, *) { + tableView.contentInsetAdjustmentBehavior = .always + } } func preiOS11Constraints() { @@ -148,7 +142,7 @@ class MDCDragonsController: UIViewController, headerViewController.headerView.backgroundColor = Constants.headerColor headerViewController.headerView.trackingScrollView = tableView view.addSubview(headerViewController.view) - headerViewController.didMove(toParentViewController: self) + headerViewController.didMove(toParent: self) } func adjustLogoForScrollView(_ scrollView: UIScrollView) { @@ -165,11 +159,11 @@ class MDCDragonsController: UIViewController, navigationController?.setNavigationBarHidden(true, animated: animated) } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return headerViewController } - override var childViewControllerForStatusBarHidden: UIViewController? { + override var childForStatusBarHidden: UIViewController? { return headerViewController } @@ -251,8 +245,8 @@ class MDCDragonsController: UIViewController, container.appBar.headerViewController.headerView.backgroundColor = headerViewController.headerView.backgroundColor container.appBar.navigationBar.tintColor = .white container.appBar.navigationBar.titleTextAttributes = - [ NSForegroundColorAttributeName: UIColor.white, - NSFontAttributeName: UIFont.systemFont(ofSize: 16) ] + [ .foregroundColor: UIColor.white, + .font: UIFont.systemFont(ofSize: 16) ] container.isTopLayoutGuideAdjustmentEnabled = true vc.title = nodeData.node.title @@ -381,17 +375,17 @@ extension MDCDragonsController { NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChangeFrame(notification:)), name: .MDCKeyboardWatcherKeyboardWillChangeFrame, object: nil) } - func keyboardWillShow(notification: NSNotification) { + @objc func keyboardWillShow(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } updateScrollViewWithKeyboardNotificationUserInfo(userInfo: userInfo) } - func keyboardWillHide(notification: NSNotification) { + @objc func keyboardWillHide(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } updateScrollViewWithKeyboardNotificationUserInfo(userInfo: userInfo) } - func keyboardWillChangeFrame(notification: NSNotification) { + @objc func keyboardWillChangeFrame(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } updateScrollViewWithKeyboardNotificationUserInfo(userInfo: userInfo) } diff --git a/catalog/MDCDragons/MDCDragonsTableViewCell.swift b/catalog/MDCDragons/MDCDragonsTableViewCell.swift index c6c7efe568d..4785fcc5bcd 100644 --- a/catalog/MDCDragons/MDCDragonsTableViewCell.swift +++ b/catalog/MDCDragons/MDCDragonsTableViewCell.swift @@ -33,7 +33,7 @@ class MDCDragonsTableViewCell: UITableViewCell { return button }() - override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) self.accessoryView = self.defaultButton } diff --git a/components/ActionSheet/BUILD b/components/ActionSheet/BUILD index cb58f351adb..bdf6fcfe711 100644 --- a/components/ActionSheet/BUILD +++ b/components/ActionSheet/BUILD @@ -113,7 +113,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], deps = [ ":ActionSheet", @@ -126,7 +126,7 @@ swift_library( srcs = glob(["tests/unit/ColorThemer/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], deps = [ ":ActionSheet", diff --git a/components/ActionSheet/tests/unit/ActionSheetTest.swift b/components/ActionSheet/tests/unit/ActionSheetTest.swift index d1d5db74a2c..0aa000c3cbb 100644 --- a/components/ActionSheet/tests/unit/ActionSheetTest.swift +++ b/components/ActionSheet/tests/unit/ActionSheetTest.swift @@ -67,7 +67,7 @@ class ActionSheetTest: XCTestCase { actionSheet.addAction(action) // Then - let tableView = actionSheet.view.subviews.flatMap{ $0 as? UITableView }.first + let tableView = actionSheet.view.subviews.compactMap { $0 as? UITableView }.first if let table = tableView { XCTAssertEqual(table.numberOfRows(inSection: section), rowCount) if let dataSource = table.dataSource { diff --git a/components/ActivityIndicator/BUILD b/components/ActivityIndicator/BUILD index 8ae78cee7b0..612655b2a54 100644 --- a/components/ActivityIndicator/BUILD +++ b/components/ActivityIndicator/BUILD @@ -68,7 +68,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/AnimationTiming/examples/AnimationTimingSwiftExampleViewController.swift b/components/AnimationTiming/examples/AnimationTimingSwiftExampleViewController.swift index fbd4576cad8..25688483f17 100644 --- a/components/AnimationTiming/examples/AnimationTimingSwiftExampleViewController.swift +++ b/components/AnimationTiming/examples/AnimationTimingSwiftExampleViewController.swift @@ -55,8 +55,8 @@ class AnimationTimingSwiftExampleViewController: UIViewController { } - func playAnimations() { - let linearCurve: CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) + @objc func playAnimations() { + let linearCurve: CAMediaTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) applyAnimation(toView: linearView, withTimingFunction: linearCurve) if let materialStandard = CAMediaTimingFunction.mdc_function(withType: .standard) { diff --git a/components/AppBar/BUILD b/components/AppBar/BUILD index ce215d9c6cc..f3228de7199 100644 --- a/components/AppBar/BUILD +++ b/components/AppBar/BUILD @@ -138,7 +138,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/AppBar/examples/AppBarAnimatedGlitchExample.swift b/components/AppBar/examples/AppBarAnimatedGlitchExample.swift index 6d24e1439c8..39fb6f6c9cb 100644 --- a/components/AppBar/examples/AppBarAnimatedGlitchExample.swift +++ b/components/AppBar/examples/AppBarAnimatedGlitchExample.swift @@ -73,11 +73,7 @@ class AppBarAnimatedJumpExample: UIViewController { view.isOpaque = false view.backgroundColor = colorScheme.backgroundColor view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif switchToTab(tabs[0], animated: false) } @@ -90,7 +86,7 @@ class AppBarAnimatedJumpExample: UIViewController { let removeOld: (() -> Void) let animateOut: (() -> Void) if let currentTab = currentTab { - currentTab.willMove(toParentViewController: nil) + currentTab.willMove(toParent: nil) animateOut = { currentTab.view.alpha = 0 @@ -99,7 +95,7 @@ class AppBarAnimatedJumpExample: UIViewController { removeOld = { currentTab.headerView = nil currentTab.view.removeFromSuperview() - currentTab.removeFromParentViewController() + currentTab.removeFromParent() } } else { removeOld = {} @@ -113,12 +109,8 @@ class AppBarAnimatedJumpExample: UIViewController { // Show new tab. view.addSubview(tab.view) - view.sendSubview(toBack: tab.view) - #if swift(>=4.2) + view.sendSubviewToBack(tab.view) tab.didMove(toParent: self) - #else - tab.didMove(toParentViewController: self) - #endif tab.headerView = self.appBarViewController.headerView tab.view.alpha = 0 @@ -162,7 +154,7 @@ class AppBarAnimatedJumpExample: UIViewController { private func makeAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - addChildViewController(appBarViewController) + addChild(appBarViewController) // Give the tab bar enough height to accomodate all possible item appearances. appBarViewController.headerView.minMaxHeightIncludesSafeArea = false @@ -178,7 +170,7 @@ class AppBarAnimatedJumpExample: UIViewController { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } } diff --git a/components/AppBar/examples/AppBarGlitchExample.swift b/components/AppBar/examples/AppBarGlitchExample.swift index 9f8428cbeef..b6419bbcd00 100644 --- a/components/AppBar/examples/AppBarGlitchExample.swift +++ b/components/AppBar/examples/AppBarGlitchExample.swift @@ -69,11 +69,7 @@ class AppBarJumpExample: UIViewController { view.backgroundColor = colorScheme.backgroundColor view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif switchToTab(firstTab) } @@ -84,9 +80,9 @@ class AppBarJumpExample: UIViewController { if let currentTab = currentTab { currentTab.headerView = nil - currentTab.willMove(toParentViewController: nil) + currentTab.willMove(toParent: nil) currentTab.view.removeFromSuperview() - currentTab.removeFromParentViewController() + currentTab.removeFromParent() } if let tabView = tab.view { @@ -95,12 +91,8 @@ class AppBarJumpExample: UIViewController { } view.addSubview(tab.view) - view.sendSubview(toBack: tab.view) - #if swift(>=4.2) + view.sendSubviewToBack(tab.view) tab.didMove(toParent: self) - #else - tab.didMove(toParentViewController: self) - #endif tab.headerView = appBarViewController.headerView @@ -123,7 +115,7 @@ class AppBarJumpExample: UIViewController { private func makeAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - addChildViewController(appBarViewController) + addChild(appBarViewController) // Give the tab bar enough height to accomodate all possible item appearances. appBarViewController.headerView.minMaxHeightIncludesSafeArea = false @@ -139,7 +131,7 @@ class AppBarJumpExample: UIViewController { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } } diff --git a/components/AppBar/examples/AppBarImageryExample.swift b/components/AppBar/examples/AppBarImageryExample.swift index 805ef71e7cf..405b75e42a6 100644 --- a/components/AppBar/examples/AppBarImageryExample.swift +++ b/components/AppBar/examples/AppBarImageryExample.swift @@ -60,11 +60,7 @@ class AppBarImagerySwiftExample: UITableViewController { headerView.trackingScrollView = self.tableView view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif } override var preferredStatusBarStyle: UIStatusBarStyle { @@ -83,7 +79,7 @@ class AppBarImagerySwiftExample: UITableViewController { appBarViewController.inferTopSafeAreaInsetFromViewController = true appBarViewController.headerView.minMaxHeightIncludesSafeArea = false - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) } required init?(coder aDecoder: NSCoder) { diff --git a/components/AppBar/examples/AppBarInheritedAnimatedJumpExample.swift b/components/AppBar/examples/AppBarInheritedAnimatedJumpExample.swift index 0dd484bc17a..957e8cd014b 100644 --- a/components/AppBar/examples/AppBarInheritedAnimatedJumpExample.swift +++ b/components/AppBar/examples/AppBarInheritedAnimatedJumpExample.swift @@ -73,11 +73,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { view.isOpaque = false view.backgroundColor = colorScheme.backgroundColor view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif switchToTab(tabs[0], animated: false) } @@ -90,7 +86,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { let removeOld: (() -> Void) let animateOut: (() -> Void) if let currentTab = currentTab { - currentTab.willMove(toParentViewController: nil) + currentTab.willMove(toParent: nil) animateOut = { currentTab.view.alpha = 0 @@ -99,7 +95,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { removeOld = { currentTab.headerView = nil currentTab.view.removeFromSuperview() - currentTab.removeFromParentViewController() + currentTab.removeFromParent() } } else { removeOld = {} @@ -113,12 +109,8 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { // Show new tab. view.addSubview(tab.view) - view.sendSubview(toBack: tab.view) - #if swift(>=4.2) + view.sendSubviewToBack(tab.view) tab.didMove(toParent: self) - #else - tab.didMove(toParentViewController: self) - #endif tab.headerView = self.appBarViewController.headerView tab.view.alpha = 0 @@ -162,7 +154,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { private func makeAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - addChildViewController(appBarViewController) + addChild(appBarViewController) // Give the tab bar enough height to accommodate all possible item appearances. appBarViewController.headerView.minMaxHeightIncludesSafeArea = false @@ -178,7 +170,7 @@ class AppBarInheritedAnimatedJumpExample: UIViewController { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } } diff --git a/components/AppBar/examples/AppBarInterfaceBuilderExampleController.swift b/components/AppBar/examples/AppBarInterfaceBuilderExampleController.swift index 64d61757d4d..43300fa0a05 100644 --- a/components/AppBar/examples/AppBarInterfaceBuilderExampleController.swift +++ b/components/AppBar/examples/AppBarInterfaceBuilderExampleController.swift @@ -45,7 +45,7 @@ class AppBarInterfaceBuilderSwiftExample: UIViewController, UIScrollViewDelegate appBarViewController.inferTopSafeAreaInsetFromViewController = true appBarViewController.headerView.minMaxHeightIncludesSafeArea = false - addChildViewController(appBarViewController) + addChild(appBarViewController) } override func viewDidLoad() { @@ -59,11 +59,7 @@ class AppBarInterfaceBuilderSwiftExample: UIViewController, UIScrollViewDelegate appBarViewController.headerView.trackingScrollView = scrollView view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif } override var preferredStatusBarStyle: UIStatusBarStyle { diff --git a/components/AppBar/examples/AppBarManualTabsExample.swift b/components/AppBar/examples/AppBarManualTabsExample.swift index 064ca0337b6..32f6f3a51e9 100644 --- a/components/AppBar/examples/AppBarManualTabsExample.swift +++ b/components/AppBar/examples/AppBarManualTabsExample.swift @@ -73,11 +73,7 @@ class AppBarManualTabsExample: UIViewController { view.backgroundColor = colorScheme.backgroundColor view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif switchToTab(firstTab) } @@ -87,9 +83,9 @@ class AppBarManualTabsExample: UIViewController { if let currentTab = currentTab { currentTab.headerView = nil - currentTab.willMove(toParentViewController: nil) + currentTab.willMove(toParent: nil) currentTab.view.removeFromSuperview() - currentTab.removeFromParentViewController() + currentTab.removeFromParent() } if let tabView = tab.view { @@ -98,13 +94,9 @@ class AppBarManualTabsExample: UIViewController { } view.addSubview(tab.tableView) - view.sendSubview(toBack: tab.tableView) + view.sendSubviewToBack(tab.tableView) - #if swift(>=4.2) tab.didMove(toParent: self) - #else - tab.didMove(toParentViewController: self) - #endif tab.headerView = appBarViewController.headerView @@ -127,7 +119,7 @@ class AppBarManualTabsExample: UIViewController { private func makeAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - addChildViewController(appBarViewController) + addChild(appBarViewController) // Give the tab bar enough height to accomodate all possible item appearances. appBarViewController.headerView.minMaxHeightIncludesSafeArea = false @@ -143,7 +135,7 @@ class AppBarManualTabsExample: UIViewController { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } } diff --git a/components/AppBar/examples/AppBarModalPresentationExample.swift b/components/AppBar/examples/AppBarModalPresentationExample.swift index 7e9daa4305d..6f209d5b711 100644 --- a/components/AppBar/examples/AppBarModalPresentationExample.swift +++ b/components/AppBar/examples/AppBarModalPresentationExample.swift @@ -35,7 +35,7 @@ class AppBarModalPresentationSwiftExamplePresented: UITableViewController { appBarViewController.inferTopSafeAreaInsetFromViewController = true appBarViewController.headerView.minMaxHeightIncludesSafeArea = false - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) self.modalPresentationStyle = .formSheet self.modalTransitionStyle = .coverVertical } @@ -55,11 +55,7 @@ class AppBarModalPresentationSwiftExamplePresented: UITableViewController { appBarViewController.headerView.trackingScrollView = self.tableView view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Touch", style: .done, target: nil, action: nil) @@ -68,11 +64,11 @@ class AppBarModalPresentationSwiftExamplePresented: UITableViewController { UIBarButtonItem(title: "Dismiss", style: .done, target: self, action: #selector(dismissSelf)) } - override var childViewControllerForStatusBarHidden: UIViewController? { + override var childForStatusBarHidden: UIViewController? { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } @@ -111,7 +107,7 @@ class AppBarModalPresentationSwiftExample: UITableViewController { self.title = "Modal Presentation (Swift)" - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) } required init?(coder aDecoder: NSCoder) { @@ -127,21 +123,17 @@ class AppBarModalPresentationSwiftExample: UITableViewController { self.tableView.delegate = appBarViewController view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Detail", style: .done, target: self, action: #selector(presentModal)) } - override var childViewControllerForStatusBarHidden: UIViewController? { + override var childForStatusBarHidden: UIViewController? { return appBarViewController } - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } diff --git a/components/AppBar/examples/AppBarTypicalUseExample.swift b/components/AppBar/examples/AppBarTypicalUseExample.swift index 6d0b37adef7..0658f0cce1f 100644 --- a/components/AppBar/examples/AppBarTypicalUseExample.swift +++ b/components/AppBar/examples/AppBarTypicalUseExample.swift @@ -39,7 +39,7 @@ class AppBarTypicalUseSwiftExample: UITableViewController { appBarViewController.headerView.minMaxHeightIncludesSafeArea = false // Step 2: Add the headerViewController as a child. - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) } required init?(coder aDecoder: NSCoder) { @@ -60,11 +60,7 @@ class AppBarTypicalUseSwiftExample: UITableViewController { // Step 2: Register the App Bar views. view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right", style: .done, target: nil, action: nil) @@ -72,13 +68,13 @@ class AppBarTypicalUseSwiftExample: UITableViewController { // Optional step: If you allow the header view to hide the status bar you must implement this // method and return the headerViewController. - override var childViewControllerForStatusBarHidden: UIViewController? { + override var childForStatusBarHidden: UIViewController? { return appBarViewController } // Optional step: The Header View Controller does basic inspection of the header view's background // color to identify whether the status bar should be light or dark-themed. - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } diff --git a/components/AppBar/examples/AppBarWithUITableViewController.swift b/components/AppBar/examples/AppBarWithUITableViewController.swift index 2d3bea4ca76..9bb51ec2901 100644 --- a/components/AppBar/examples/AppBarWithUITableViewController.swift +++ b/components/AppBar/examples/AppBarWithUITableViewController.swift @@ -43,7 +43,7 @@ class AppBarWithUITableViewController: UITableViewController { commonInit() } - override init(style: UITableViewStyle) { + override init(style: UITableView.Style) { super.init(style: style) commonInit() } @@ -54,7 +54,7 @@ class AppBarWithUITableViewController: UITableViewController { appBarViewController.inferTopSafeAreaInsetFromViewController = true appBarViewController.headerView.minMaxHeightIncludesSafeArea = false - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) } override func viewDidLoad() { @@ -64,11 +64,7 @@ class AppBarWithUITableViewController: UITableViewController { appBarViewController.headerView.observesTrackingScrollViewScrollEvents = true view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif MDCAppBarColorThemer.applyColorScheme(colorScheme, to: appBarViewController) diff --git a/components/AppBar/tests/unit/AppBarNavigationControllerTests.swift b/components/AppBar/tests/unit/AppBarNavigationControllerTests.swift index 4aae008e37b..3c0eab8615b 100644 --- a/components/AppBar/tests/unit/AppBarNavigationControllerTests.swift +++ b/components/AppBar/tests/unit/AppBarNavigationControllerTests.swift @@ -48,7 +48,7 @@ class AppBarNavigationControllerTests: XCTestCase { let navigationController = MDCAppBarNavigationController(rootViewController: viewController) // Then - XCTAssertEqual(viewController.childViewControllers.count, 1, + XCTAssertEqual(viewController.children.count, 1, "Expected there to be exactly one child view controller added to the view" + " controller.") @@ -56,12 +56,12 @@ class AppBarNavigationControllerTests: XCTestCase { "The navigation controller's top view controller is supposed to be the pushed" + " view controller, but it is \(viewController).") - XCTAssertTrue(viewController.childViewControllers.first is MDCFlexibleHeaderViewController, + XCTAssertTrue(viewController.children.first is MDCFlexibleHeaderViewController, "The injected view controller is not a flexible header view controller, it is" - + "\(String(describing: viewController.childViewControllers.first)) instead.") + + "\(String(describing: viewController.children.first)) instead.") if let headerViewController - = viewController.childViewControllers.first as? MDCFlexibleHeaderViewController { + = viewController.children.first as? MDCFlexibleHeaderViewController { XCTAssertEqual(headerViewController.headerView.frame.height, headerViewController.headerView.maximumHeight) } @@ -75,7 +75,7 @@ class AppBarNavigationControllerTests: XCTestCase { navigationController.pushViewController(viewController, animated: false) // Then - XCTAssertEqual(viewController.childViewControllers.count, 1, + XCTAssertEqual(viewController.children.count, 1, "Expected there to be exactly one child view controller added to the view" + " controller.") @@ -83,12 +83,12 @@ class AppBarNavigationControllerTests: XCTestCase { "The navigation controller's top view controller is supposed to be the pushed" + " view controller, but it is \(viewController).") - XCTAssertTrue(viewController.childViewControllers.first is MDCFlexibleHeaderViewController, + XCTAssertTrue(viewController.children.first is MDCFlexibleHeaderViewController, "The injected view controller is not a flexible header view controller, it is" - + "\(String(describing: viewController.childViewControllers.first)) instead.") + + "\(String(describing: viewController.children.first)) instead.") if let headerViewController - = viewController.childViewControllers.first as? MDCFlexibleHeaderViewController { + = viewController.children.first as? MDCFlexibleHeaderViewController { XCTAssertEqual(headerViewController.headerView.frame.height, headerViewController.headerView.maximumHeight) } @@ -102,7 +102,7 @@ class AppBarNavigationControllerTests: XCTestCase { navigationController.viewControllers = [viewController] // Then - XCTAssertEqual(viewController.childViewControllers.count, 1, + XCTAssertEqual(viewController.children.count, 1, "Expected there to be exactly one child view controller added to the view" + " controller.") @@ -110,12 +110,12 @@ class AppBarNavigationControllerTests: XCTestCase { "The navigation controller's top view controller is supposed to be the pushed" + " view controller, but it is \(viewController).") - XCTAssertTrue(viewController.childViewControllers.first is MDCFlexibleHeaderViewController, + XCTAssertTrue(viewController.children.first is MDCFlexibleHeaderViewController, "The injected view controller is not a flexible header view controller, it is" - + "\(String(describing: viewController.childViewControllers.first)) instead.") + + "\(String(describing: viewController.children.first)) instead.") if let headerViewController - = viewController.childViewControllers.first as? MDCFlexibleHeaderViewController { + = viewController.children.first as? MDCFlexibleHeaderViewController { XCTAssertEqual(headerViewController.headerView.frame.height, headerViewController.headerView.maximumHeight) } @@ -129,7 +129,7 @@ class AppBarNavigationControllerTests: XCTestCase { navigationController.setViewControllers([viewController], animated: false) // Then - XCTAssertEqual(viewController.childViewControllers.count, 1, + XCTAssertEqual(viewController.children.count, 1, "Expected there to be exactly one child view controller added to the view" + " controller.") @@ -137,12 +137,12 @@ class AppBarNavigationControllerTests: XCTestCase { "The navigation controller's top view controller is supposed to be the pushed" + " view controller, but it is \(viewController).") - XCTAssertTrue(viewController.childViewControllers.first is MDCFlexibleHeaderViewController, + XCTAssertTrue(viewController.children.first is MDCFlexibleHeaderViewController, "The injected view controller is not a flexible header view controller, it is" - + "\(String(describing: viewController.childViewControllers.first)) instead.") + + "\(String(describing: viewController.children.first)) instead.") if let headerViewController - = viewController.childViewControllers.first as? MDCFlexibleHeaderViewController { + = viewController.children.first as? MDCFlexibleHeaderViewController { XCTAssertEqual(headerViewController.headerView.frame.height, headerViewController.headerView.maximumHeight) } @@ -157,7 +157,7 @@ class AppBarNavigationControllerTests: XCTestCase { navigationController.pushViewController(container, animated: false) // Then - XCTAssertEqual(container.childViewControllers.count, 2, + XCTAssertEqual(container.children.count, 2, "An App Bar container view controller should have exactly two child view" + " controllers. A failure of this assertion implies that the navigation" + " controller may have injected another App Bar.") @@ -168,19 +168,15 @@ class AppBarNavigationControllerTests: XCTestCase { let viewController = UIViewController() let container = MDCAppBarContainerViewController(contentViewController: viewController) let nestedContainer = UIViewController() - nestedContainer.addChildViewController(container) + nestedContainer.addChild(container) nestedContainer.view.addSubview(container.view) - #if swift(>=4.2) container.didMove(toParent: nestedContainer) - #else - container.didMove(toParentViewController: nestedContainer) - #endif // When navigationController.pushViewController(nestedContainer, animated: false) // Then - XCTAssertEqual(nestedContainer.childViewControllers.count, 1, + XCTAssertEqual(nestedContainer.children.count, 1, "The view controller hierarchy already has one app bar view controller, but it" + " appears to have possibly added another.") } @@ -189,19 +185,15 @@ class AppBarNavigationControllerTests: XCTestCase { // Given let viewController = UIViewController() let fhvc = MDCFlexibleHeaderViewController() - viewController.addChildViewController(fhvc) + viewController.addChild(fhvc) viewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: viewController) - #else - fhvc.didMove(toParentViewController: viewController) - #endif // When navigationController.pushViewController(viewController, animated: false) // Then - XCTAssertEqual(viewController.childViewControllers.count, 1, + XCTAssertEqual(viewController.children.count, 1, "The navigation controller may have injected another App Bar when it shouldn't" + " have.") } @@ -219,7 +211,7 @@ class AppBarNavigationControllerTests: XCTestCase { XCTAssertNotNil(appBar, "Could not retrieve the injected App Bar.") if let appBar = appBar { - XCTAssertEqual(navigationController.childViewControllerForStatusBarStyle, + XCTAssertEqual(navigationController.childForStatusBarStyle, appBar.headerViewController, "The navigation controller should be using the injected app bar's flexible" + "header view controller for status bar style updates.") diff --git a/components/AppBar/tests/unit/AppBarTypographyThemerTests.swift b/components/AppBar/tests/unit/AppBarTypographyThemerTests.swift index dfcfad03108..44058ae65bb 100644 --- a/components/AppBar/tests/unit/AppBarTypographyThemerTests.swift +++ b/components/AppBar/tests/unit/AppBarTypographyThemerTests.swift @@ -20,8 +20,8 @@ import MaterialComponents.MaterialTypography class AppBarTypographyThemerTests: XCTestCase { func traitsForFont(_ font: UIFont) -> [String: NSNumber] { - guard let fontTraits = - font.fontDescriptor.object(forKey: UIFontDescriptorTraitsAttribute) as? [String: NSNumber] + guard let fontTraits = font.fontDescriptor.object(forKey: UIFontDescriptor.AttributeName.traits) + as? [String: NSNumber] else { return [:] } diff --git a/components/AppBar/tests/unit/AppBarWrappingLegacyTopLayoutGuideTests.swift b/components/AppBar/tests/unit/AppBarWrappingLegacyTopLayoutGuideTests.swift index 30132fc7f86..10ae81cf1ab 100644 --- a/components/AppBar/tests/unit/AppBarWrappingLegacyTopLayoutGuideTests.swift +++ b/components/AppBar/tests/unit/AppBarWrappingLegacyTopLayoutGuideTests.swift @@ -34,11 +34,9 @@ class AppBarWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertNil(container.appBar.headerViewController.topLayoutGuideViewController) XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) } - #endif } // MARK: Untracked table view @@ -57,12 +55,10 @@ class AppBarWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertNil(container.appBar.headerViewController.topLayoutGuideViewController) XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked table view @@ -84,14 +80,12 @@ class AppBarWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertNil(container.appBar.headerViewController.topLayoutGuideViewController) XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, container.appBar.headerViewController.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Untracked collection view @@ -111,12 +105,10 @@ class AppBarWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertNil(container.appBar.headerViewController.topLayoutGuideViewController) XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view @@ -140,14 +132,12 @@ class AppBarWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertNil(container.appBar.headerViewController.topLayoutGuideViewController) XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, container.appBar.headerViewController.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } } diff --git a/components/AppBar/tests/unit/AppBarWrappingTopLayoutGuideTests.swift b/components/AppBar/tests/unit/AppBarWrappingTopLayoutGuideTests.swift index 971bb82e8d3..42e41dfd5d8 100644 --- a/components/AppBar/tests/unit/AppBarWrappingTopLayoutGuideTests.swift +++ b/components/AppBar/tests/unit/AppBarWrappingTopLayoutGuideTests.swift @@ -36,13 +36,11 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.appBar.headerViewController.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) } - #endif } func testEarlyViewLoadStillAffectsTopLayoutGuide() { @@ -61,13 +59,11 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.appBar.headerViewController.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Untracked table view @@ -88,14 +84,12 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.appBar.headerViewController.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked table view @@ -119,13 +113,11 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, container.appBar.headerViewController.headerView.maximumHeight) } - #endif } // MARK: Untracked collection view @@ -148,14 +140,12 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.appBar.headerViewController.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view view @@ -182,13 +172,11 @@ class AppBarWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.appBar.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, container.appBar.headerViewController.headerView.maximumHeight) } - #endif } } diff --git a/components/BottomAppBar/examples/BottomAppBarTypicalUseExample.swift b/components/BottomAppBar/examples/BottomAppBarTypicalUseExample.swift index 1f6be75a862..43a76494495 100644 --- a/components/BottomAppBar/examples/BottomAppBarTypicalUseExample.swift +++ b/components/BottomAppBar/examples/BottomAppBarTypicalUseExample.swift @@ -34,12 +34,13 @@ class BottomAppBarTypicalUseSwiftExample: UIViewController { super.init(nibName: nil, bundle: nil) self.title = "Bottom App Bar (Swift)" - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) let color = UIColor(white: 0.2, alpha:1) appBarViewController.headerView.backgroundColor = color appBarViewController.navigationBar.tintColor = .white - appBarViewController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white] + appBarViewController.navigationBar.titleTextAttributes = + [NSAttributedString.Key.foregroundColor : UIColor.white] commonInitBottomAppBarTypicalUseSwiftExample() } @@ -52,11 +53,7 @@ class BottomAppBarTypicalUseSwiftExample: UIViewController { super.viewDidLoad() view.addSubview(appBarViewController.view) - #if swift(>=4.2) appBarViewController.didMove(toParent: self) - #else - appBarViewController.didMove(toParentViewController: self) - #endif } func commonInitBottomAppBarTypicalUseSwiftExample() { @@ -133,14 +130,11 @@ class BottomAppBarTypicalUseSwiftExample: UIViewController { layoutBottomAppBar() } - #if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() layoutBottomAppBar() } - #endif - } // MARK: Catalog by convention diff --git a/components/BottomNavigation/BUILD b/components/BottomNavigation/BUILD index 1739b88d612..94f9ae925ff 100644 --- a/components/BottomNavigation/BUILD +++ b/components/BottomNavigation/BUILD @@ -147,7 +147,7 @@ swift_library( ), copts = [ "-swift-version", - "3", + "4.2", ], deps = [ ":BottomNavigationBeta", diff --git a/components/BottomNavigation/examples/BottomNavigationExplicitlySetColorExample.swift b/components/BottomNavigation/examples/BottomNavigationExplicitlySetColorExample.swift index 41c1cd742d8..205df7d5453 100644 --- a/components/BottomNavigation/examples/BottomNavigationExplicitlySetColorExample.swift +++ b/components/BottomNavigation/examples/BottomNavigationExplicitlySetColorExample.swift @@ -61,13 +61,11 @@ class BottomNavigationExplicitlySetColorExample: UIViewController { layoutBottomNavBar() } - #if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() layoutBottomNavBar() } - #endif override func viewDidLoad() { super.viewDidLoad() diff --git a/components/BottomNavigation/examples/BottomNavigationNilBadges.swift b/components/BottomNavigation/examples/BottomNavigationNilBadges.swift index f0154bd52fc..6a8dfcddf07 100644 --- a/components/BottomNavigation/examples/BottomNavigationNilBadges.swift +++ b/components/BottomNavigation/examples/BottomNavigationNilBadges.swift @@ -82,13 +82,11 @@ class BottomNavigationNilBadges : UIViewController { layoutBottomNavBar() } - #if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() layoutBottomNavBar() } - #endif override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) diff --git a/components/BottomNavigation/examples/BottomNavigationResetButtons.swift b/components/BottomNavigation/examples/BottomNavigationResetButtons.swift index 72fa00e7c53..02ba7707913 100644 --- a/components/BottomNavigation/examples/BottomNavigationResetButtons.swift +++ b/components/BottomNavigation/examples/BottomNavigationResetButtons.swift @@ -74,13 +74,11 @@ class BottomNavigationResetExample: UIViewController { layoutBottomNavBar() } - #if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() layoutBottomNavBar() } - #endif override func viewDidLoad() { super.viewDidLoad() diff --git a/components/BottomNavigation/examples/BottomNavigationSelectedIconExample.swift b/components/BottomNavigation/examples/BottomNavigationSelectedIconExample.swift index 2ef25607650..1128705b17e 100644 --- a/components/BottomNavigation/examples/BottomNavigationSelectedIconExample.swift +++ b/components/BottomNavigation/examples/BottomNavigationSelectedIconExample.swift @@ -61,13 +61,11 @@ class BottomNavigationSelectedIconExample: UIViewController { layoutBottomNavBar() } - #if swift(>=3.2) @available(iOS 11, *) override func viewSafeAreaInsetsDidChange() { super.viewSafeAreaInsetsDidChange() layoutBottomNavBar() } - #endif } diff --git a/components/BottomNavigation/examples/BottomNavigationTitleVisibilityChangeExample.swift b/components/BottomNavigation/examples/BottomNavigationTitleVisibilityChangeExample.swift index 53b748931d7..e1b8c402f06 100644 --- a/components/BottomNavigation/examples/BottomNavigationTitleVisibilityChangeExample.swift +++ b/components/BottomNavigation/examples/BottomNavigationTitleVisibilityChangeExample.swift @@ -87,7 +87,7 @@ class BottomNavigationTitleVisibilityChangeExample: UIViewController, MDCBottomN var viewBounds = view.bounds; if #available(iOS 11.0, *) { - viewBounds = UIEdgeInsetsInsetRect(viewBounds, view.safeAreaInsets) + viewBounds = viewBounds.inset(by: view.safeAreaInsets) } let labelWidth = min(viewBounds.size.width - 32, 480); let labelSize = instructionLabel.sizeThatFits(CGSize(width: labelWidth, diff --git a/components/BottomSheet/BUILD b/components/BottomSheet/BUILD index 4cf949f0a5c..dce0bacb462 100644 --- a/components/BottomSheet/BUILD +++ b/components/BottomSheet/BUILD @@ -109,7 +109,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/ButtonBar/BUILD b/components/ButtonBar/BUILD index f215882cc39..77bec95f5e0 100644 --- a/components/ButtonBar/BUILD +++ b/components/ButtonBar/BUILD @@ -122,7 +122,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/ButtonBar/examples/ButtonBarTypicalUseExample.swift b/components/ButtonBar/examples/ButtonBarTypicalUseExample.swift index 4078c123c5f..5882f169cd8 100644 --- a/components/ButtonBar/examples/ButtonBarTypicalUseExample.swift +++ b/components/ButtonBar/examples/ButtonBarTypicalUseExample.swift @@ -35,7 +35,7 @@ class ButtonBarTypicalUseSwiftExample: UIViewController { buttonBar.applyPrimaryTheme(withScheme: scheme) // MDCButtonBar ignores the style of UIBarButtonItem. - let ignored: UIBarButtonItemStyle = .done + let ignored: UIBarButtonItem.Style = .done let actionItem = UIBarButtonItem( title: "Action", diff --git a/components/ButtonBar/tests/unit/ButtonBarIssue370Tests.swift b/components/ButtonBar/tests/unit/ButtonBarIssue370Tests.swift index d3b21c1eb97..ec4c9699447 100644 --- a/components/ButtonBar/tests/unit/ButtonBarIssue370Tests.swift +++ b/components/ButtonBar/tests/unit/ButtonBarIssue370Tests.swift @@ -23,21 +23,21 @@ import MaterialComponents.MaterialButtons class ButtonBarIssue370Tests: XCTestCase { var buttonBar: MDCButtonBar! - let globalAttributes = [NSForegroundColorAttributeName: UIColor.blue] - let directAttributes = [NSForegroundColorAttributeName: UIColor.blue] - let fontAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 12)] + let globalAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue] + let directAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue] + let fontAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12)] override func setUp() { buttonBar = MDCButtonBar() } override func tearDown() { - UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: UIControlState()) + UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: UIControl.State()) } func testDirectOnly() { let item = UIBarButtonItem(title: "Text", style: .plain, target: nil, action: nil) - item.setTitleTextAttributes(directAttributes, for: UIControlState()) + item.setTitleTextAttributes(directAttributes, for: UIControl.State()) buttonBar.items = [item] forEachButton { button in @@ -47,9 +47,9 @@ class ButtonBarIssue370Tests: XCTestCase { } func testGlobalAppearanceOnly() { - UIBarButtonItem.appearance().setTitleTextAttributes(globalAttributes, for: UIControlState()) + UIBarButtonItem.appearance().setTitleTextAttributes(globalAttributes, for: UIControl.State()) - if UIBarButtonItem.appearance().titleTextAttributes(for: UIControlState()) == nil { + if UIBarButtonItem.appearance().titleTextAttributes(for: UIControl.State()) == nil { // This feature is not supported on this OS return } @@ -64,12 +64,12 @@ class ButtonBarIssue370Tests: XCTestCase { } func testGlobalAppearanceAndDirectOverwriting() { - UIBarButtonItem.appearance().setTitleTextAttributes(globalAttributes, for: UIControlState()) + UIBarButtonItem.appearance().setTitleTextAttributes(globalAttributes, for: UIControl.State()) let item = UIBarButtonItem(title: "Text", style: .plain, target: nil, action: nil) // Should take priority. - item.setTitleTextAttributes(directAttributes, for: UIControlState()) + item.setTitleTextAttributes(directAttributes, for: UIControl.State()) buttonBar.items = [item] @@ -80,18 +80,18 @@ class ButtonBarIssue370Tests: XCTestCase { } func testGlobalAppearanceAndDirectMerging() { - UIBarButtonItem.appearance().setTitleTextAttributes(fontAttributes, for: UIControlState()) + UIBarButtonItem.appearance().setTitleTextAttributes(fontAttributes, for: UIControl.State()) - if UIBarButtonItem.appearance().titleTextAttributes(for: UIControlState()) == nil { + if UIBarButtonItem.appearance().titleTextAttributes(for: UIControl.State()) == nil { // This feature is not supported on this OS return } let item = UIBarButtonItem(title: "Text", style: .plain, target: nil, action: nil) - item.setTitleTextAttributes(directAttributes, for: UIControlState()) + item.setTitleTextAttributes(directAttributes, for: UIControl.State()) buttonBar.items = [item] - var composite: [String: Any] = fontAttributes + var composite: [NSAttributedString.Key: Any] = fontAttributes for (key, value) in directAttributes { composite[key] = value } diff --git a/components/ButtonBar/tests/unit/ButtonBarIssue516Tests.swift b/components/ButtonBar/tests/unit/ButtonBarIssue516Tests.swift index b3d8819a458..7aa44924bf6 100644 --- a/components/ButtonBar/tests/unit/ButtonBarIssue516Tests.swift +++ b/components/ButtonBar/tests/unit/ButtonBarIssue516Tests.swift @@ -42,8 +42,8 @@ class ButtonBarIssue516Tests: XCTestCase { buttons = buttons.sorted { (button1, button2) -> Bool in return button1.frame.origin.x < button2.frame.origin.x } - XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControlState()), "LEFT") - XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControlState()), "RIGHT") + XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControl.State()), "LEFT") + XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControl.State()), "RIGHT") } func testLayoutPositionLeading() { @@ -59,8 +59,8 @@ class ButtonBarIssue516Tests: XCTestCase { buttons = buttons.sorted { (button1, button2) -> Bool in return button1.frame.origin.x < button2.frame.origin.x } - XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControlState()), "LEFT") - XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControlState()), "RIGHT") + XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControl.State()), "LEFT") + XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControl.State()), "RIGHT") } func testLayoutPositionTrailing() { @@ -76,7 +76,7 @@ class ButtonBarIssue516Tests: XCTestCase { buttons = buttons.sorted { (button1, button2) -> Bool in return button1.frame.origin.x < button2.frame.origin.x } - XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControlState()), "RIGHT") - XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControlState()), "LEFT") + XCTAssertEqual((buttons[0] as! MDCButton).title(for: UIControl.State()), "RIGHT") + XCTAssertEqual((buttons[1] as! MDCButton).title(for: UIControl.State()), "LEFT") } } diff --git a/components/ButtonBar/tests/unit/ButtonBarObservationTests.swift b/components/ButtonBar/tests/unit/ButtonBarObservationTests.swift index 972905927a0..98d154dc604 100644 --- a/components/ButtonBar/tests/unit/ButtonBarObservationTests.swift +++ b/components/ButtonBar/tests/unit/ButtonBarObservationTests.swift @@ -45,7 +45,7 @@ class ButtonBarObservationTests: XCTestCase { buttonBar.layoutSubviews() // Then - let titles = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.title(for: .normal) } + let titles = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.title(for: .normal) } XCTAssertEqual(titles, [item.title!]) } @@ -60,7 +60,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let images = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.image(for: .normal) } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.image(for: .normal) } XCTAssertEqual(images, [item.image!]) } @@ -81,22 +81,22 @@ class ButtonBarObservationTests: XCTestCase { // Then let accessibilityHints = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityHint } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityHint } XCTAssertEqual(accessibilityHints, [item.accessibilityHint!]) let accessibilityIdentifiers = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityIdentifier } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityIdentifier } XCTAssertEqual(accessibilityIdentifiers, [item.accessibilityIdentifier!]) let accessibilityLabels = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityLabel } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityLabel } XCTAssertEqual(accessibilityLabels, [item.accessibilityLabel!]) let accessibilityValues = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityValue } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityValue } XCTAssertEqual(accessibilityValues, [item.accessibilityValue!]) - let enabled = buttonBar.subviews.flatMap { $0 as? MDCButton }.map { $0.isEnabled } + let enabled = buttonBar.subviews.compactMap { $0 as? MDCButton }.map { $0.isEnabled } XCTAssertEqual(enabled, [item.isEnabled]) - let tags = buttonBar.subviews.flatMap { $0 as? MDCButton }.map { $0.tag } + let tags = buttonBar.subviews.compactMap { $0 as? MDCButton }.map { $0.tag } XCTAssertEqual(tags, [item.tag]) - let tintColors = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.tintColor } + let tintColors = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.tintColor } XCTAssertEqual(tintColors, [item.tintColor!]) } @@ -114,7 +114,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let accessibilityLabels = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityHint } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityHint } XCTAssertEqual(accessibilityLabels, [item.accessibilityHint!]) } @@ -130,7 +130,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let accessibilityIdentifiers = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityIdentifier } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityIdentifier } XCTAssertEqual(accessibilityIdentifiers, [item.accessibilityIdentifier!]) } @@ -146,7 +146,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let accessibilityLabels = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityLabel } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityLabel } XCTAssertEqual(accessibilityLabels, [item.accessibilityLabel!]) } @@ -162,7 +162,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let accessibilityValues = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.accessibilityValue } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.accessibilityValue } XCTAssertEqual(accessibilityValues, [item.accessibilityValue!]) } @@ -177,7 +177,7 @@ class ButtonBarObservationTests: XCTestCase { item.isEnabled = false // Then - let enabled = buttonBar.subviews.flatMap { $0 as? MDCButton }.map { $0.isEnabled } + let enabled = buttonBar.subviews.compactMap { $0 as? MDCButton }.map { $0.isEnabled } XCTAssertEqual(enabled, [item.isEnabled]) } @@ -193,7 +193,7 @@ class ButtonBarObservationTests: XCTestCase { // Then let images = - buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.image(for: .normal) } + buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.image(for: .normal) } XCTAssertEqual(images, [item.image!]) } @@ -208,7 +208,7 @@ class ButtonBarObservationTests: XCTestCase { item.tag = 50 // Then - let tags = buttonBar.subviews.flatMap { $0 as? MDCButton }.map { $0.tag } + let tags = buttonBar.subviews.compactMap { $0 as? MDCButton }.map { $0.tag } XCTAssertEqual(tags, [item.tag]) } @@ -223,14 +223,14 @@ class ButtonBarObservationTests: XCTestCase { item.tintColor = .red // Then - let tintColors = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.tintColor } + let tintColors = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.tintColor } XCTAssertEqual(tintColors, [item.tintColor!]) // Verify that the tint color reverts to the default item.tintColor = nil do { - let tintColors = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.tintColor } + let tintColors = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.tintColor } XCTAssertEqual(tintColors, [buttonBar.tintColor]) } } @@ -246,7 +246,7 @@ class ButtonBarObservationTests: XCTestCase { item.tintColor = nil // Then - let tintColors = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.tintColor } + let tintColors = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.tintColor } XCTAssertEqual(tintColors, [buttonBar.tintColor]) } @@ -260,7 +260,7 @@ class ButtonBarObservationTests: XCTestCase { item.title = "NEW TITLE" // Then - let titles = buttonBar.subviews.flatMap { $0 as? MDCButton }.flatMap { $0.title(for: .normal) } + let titles = buttonBar.subviews.compactMap { $0 as? MDCButton }.compactMap { $0.title(for: .normal) } XCTAssertEqual(titles, [item.title!]) } diff --git a/components/Buttons/BUILD b/components/Buttons/BUILD index 2af2563f89f..6edb311ce86 100644 --- a/components/Buttons/BUILD +++ b/components/Buttons/BUILD @@ -181,7 +181,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/Buttons/examples/ButtonsCustomFontViewController.swift b/components/Buttons/examples/ButtonsCustomFontViewController.swift index f25f746836e..b948c759a23 100644 --- a/components/Buttons/examples/ButtonsCustomFontViewController.swift +++ b/components/Buttons/examples/ButtonsCustomFontViewController.swift @@ -43,7 +43,7 @@ class ButtonsCustomFontViewController: UIViewController { view.backgroundColor = containerScheme.colorScheme.backgroundColor let flatButtonStatic = MDCButton() flatButtonStatic.applyContainedTheme(withScheme: containerScheme) - flatButtonStatic.setTitle("Static", for: UIControlState()) + flatButtonStatic.setTitle("Static", for: UIControl.State()) flatButtonStatic.sizeToFit() flatButtonStatic.translatesAutoresizingMaskIntoConstraints = false flatButtonStatic.addTarget(self, action: #selector(tap), for: .touchUpInside) @@ -51,7 +51,7 @@ class ButtonsCustomFontViewController: UIViewController { let flatButtonDynamic = MDCButton() flatButtonDynamic.applyContainedTheme(withScheme: containerScheme) - flatButtonDynamic.setTitle("Dynamic", for: UIControlState()) + flatButtonDynamic.setTitle("Dynamic", for: UIControl.State()) flatButtonDynamic.sizeToFit() flatButtonDynamic.translatesAutoresizingMaskIntoConstraints = false flatButtonDynamic.addTarget(self, action: #selector(tap), for: .touchUpInside) diff --git a/components/Buttons/examples/ButtonsDynamicTypeViewController.swift b/components/Buttons/examples/ButtonsDynamicTypeViewController.swift index 0dad5b8d4a8..d155decfb07 100644 --- a/components/Buttons/examples/ButtonsDynamicTypeViewController.swift +++ b/components/Buttons/examples/ButtonsDynamicTypeViewController.swift @@ -41,7 +41,7 @@ class ButtonsDynamicTypeViewController: UIViewController { flatButtonStatic.applyContainedTheme(withScheme: containerScheme) flatButtonStatic.setTitleColor(titleColor, for: .normal) flatButtonStatic.setBackgroundColor(backgroundColor, for: .normal) - flatButtonStatic.setTitle("Static", for: UIControlState()) + flatButtonStatic.setTitle("Static", for: UIControl.State()) flatButtonStatic.sizeToFit() flatButtonStatic.translatesAutoresizingMaskIntoConstraints = false flatButtonStatic.addTarget(self, action: #selector(tap), for: .touchUpInside) @@ -52,7 +52,7 @@ class ButtonsDynamicTypeViewController: UIViewController { flatButtonDynamic.applyContainedTheme(withScheme: containerScheme) flatButtonDynamic.setTitleColor(titleColor, for: .normal) flatButtonDynamic.setBackgroundColor(backgroundColor, for: .normal) - flatButtonDynamic.setTitle("Dynamic", for: UIControlState()) + flatButtonDynamic.setTitle("Dynamic", for: UIControl.State()) flatButtonDynamic.sizeToFit() flatButtonDynamic.translatesAutoresizingMaskIntoConstraints = false flatButtonDynamic.addTarget(self, action: #selector(tap), for: .touchUpInside) @@ -64,7 +64,7 @@ class ButtonsDynamicTypeViewController: UIViewController { flatButtonDynamicLegacy.applyContainedTheme(withScheme: containerScheme) flatButtonDynamicLegacy.setTitleColor(titleColor, for: .normal) flatButtonDynamicLegacy.setBackgroundColor(backgroundColor, for: .normal) - flatButtonDynamicLegacy.setTitle("Dynamic (legacy)", for: UIControlState()) + flatButtonDynamicLegacy.setTitle("Dynamic (legacy)", for: UIControl.State()) flatButtonDynamicLegacy.sizeToFit() flatButtonDynamicLegacy.translatesAutoresizingMaskIntoConstraints = false flatButtonDynamicLegacy.addTarget(self, action: #selector(tap), for: .touchUpInside) diff --git a/components/Buttons/examples/ButtonsSimpleExampleSwiftViewController.swift b/components/Buttons/examples/ButtonsSimpleExampleSwiftViewController.swift index b1f12fdb494..500eb4785f4 100644 --- a/components/Buttons/examples/ButtonsSimpleExampleSwiftViewController.swift +++ b/components/Buttons/examples/ButtonsSimpleExampleSwiftViewController.swift @@ -35,30 +35,30 @@ class ButtonsSimpleExampleSwiftViewController: UIViewController { let containedButton = MDCButton() containedButton.applyContainedTheme(withScheme: containerScheme) - containedButton.setTitle("Tap Me Too", for: UIControlState()) + containedButton.setTitle("Tap Me Too", for: UIControl.State()) containedButton.sizeToFit() let containedButtonVerticalInset = min(0, -(kMinimumAccessibleButtonSize.height - containedButton.bounds.height) / 2); let containedButtonHorizontalInset = min(0, -(kMinimumAccessibleButtonSize.width - containedButton.bounds.width) / 2); containedButton.hitAreaInsets = - UIEdgeInsetsMake(containedButtonVerticalInset, containedButtonHorizontalInset, - containedButtonVerticalInset, containedButtonHorizontalInset); + UIEdgeInsets(top: containedButtonVerticalInset, left: containedButtonHorizontalInset, + bottom: containedButtonVerticalInset, right: containedButtonHorizontalInset) containedButton.translatesAutoresizingMaskIntoConstraints = false containedButton.addTarget(self, action: #selector(tap), for: .touchUpInside) view.addSubview(containedButton) let textButton = MDCButton() textButton.applyTextTheme(withScheme: MDCContainerScheme()) - textButton.setTitle("Touch me", for: UIControlState()) + textButton.setTitle("Touch me", for: UIControl.State()) textButton.sizeToFit() let textButtonVerticalInset = min(0, -(kMinimumAccessibleButtonSize.height - textButton.bounds.height) / 2); let textButtonHorizontalInset = min(0, -(kMinimumAccessibleButtonSize.width - textButton.bounds.width) / 2); textButton.hitAreaInsets = - UIEdgeInsetsMake(textButtonVerticalInset, textButtonHorizontalInset, - textButtonVerticalInset, textButtonHorizontalInset); + UIEdgeInsets(top: textButtonVerticalInset, left: textButtonHorizontalInset, + bottom: textButtonVerticalInset, right: textButtonHorizontalInset) textButton.translatesAutoresizingMaskIntoConstraints = false textButton.addTarget(self, action: #selector(tap), for: .touchUpInside) view.addSubview(textButton) diff --git a/components/Buttons/examples/ButtonsStoryboardAndProgrammatic.swift b/components/Buttons/examples/ButtonsStoryboardAndProgrammatic.swift index df679b9f387..82e964c9859 100644 --- a/components/Buttons/examples/ButtonsStoryboardAndProgrammatic.swift +++ b/components/Buttons/examples/ButtonsStoryboardAndProgrammatic.swift @@ -97,11 +97,9 @@ class ButtonsSwiftAndStoryboardController: UIViewController { private func layoutContainer() { let viewLayoutGuide: Any = { - #if swift(>=3.2) - if #available(iOS 11.0, *) { - return view.safeAreaLayoutGuide - } - #endif + if #available(iOS 11.0, *) { + return view.safeAreaLayoutGuide + } return view }() NSLayoutConstraint.activate([ diff --git a/components/Buttons/examples/FloatingButtonExampleSwiftViewController.swift b/components/Buttons/examples/FloatingButtonExampleSwiftViewController.swift index 55b956c9283..97fb726cb52 100644 --- a/components/Buttons/examples/FloatingButtonExampleSwiftViewController.swift +++ b/components/Buttons/examples/FloatingButtonExampleSwiftViewController.swift @@ -52,7 +52,7 @@ class FloatingButtonExampleSwiftViewController: UIViewController { largeIconFloatingButton.translatesAutoresizingMaskIntoConstraints = false largeIconFloatingButton.setImage(plusImage36, for: .normal) largeIconFloatingButton.accessibilityLabel = "Create" - largeIconFloatingButton.setContentEdgeInsets(UIEdgeInsetsMake(-6, -6, -6, 0), for: .default, + largeIconFloatingButton.setContentEdgeInsets(UIEdgeInsets(top: -6, left: -6, bottom: -6, right: 0), for: .default, in: .expanded) largeIconFloatingButton.applySecondaryTheme(withScheme: containerScheme) diff --git a/components/Cards/BUILD b/components/Cards/BUILD index 7e943dc3b92..379337e1d1c 100644 --- a/components/Cards/BUILD +++ b/components/Cards/BUILD @@ -89,7 +89,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/Cards/examples/EditReorderCollectionViewController.swift b/components/Cards/examples/EditReorderCollectionViewController.swift index 6620882d826..79639fac494 100644 --- a/components/Cards/examples/EditReorderCollectionViewController.swift +++ b/components/Cards/examples/EditReorderCollectionViewController.swift @@ -83,21 +83,17 @@ class EditReorderCollectionViewController: UIViewController, dataSource.append((image: images[ind].image, title: images[ind].title, selected: false)) } - #if swift(>=3.2) - if #available(iOS 11, *) { - let guide = view.safeAreaLayoutGuide - NSLayoutConstraint.activate([ - collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), - collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), - collectionView.topAnchor.constraint(equalTo: view.topAnchor), - collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) - collectionView.contentInsetAdjustmentBehavior = .always - } else { - preiOS11Constraints() - } - #else + if #available(iOS 11, *) { + let guide = view.safeAreaLayoutGuide + NSLayoutConstraint.activate([ + collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), + collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), + collectionView.topAnchor.constraint(equalTo: view.topAnchor), + collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) + collectionView.contentInsetAdjustmentBehavior = .always + } else { preiOS11Constraints() - #endif + } self.updateTitle() } @@ -124,7 +120,7 @@ class EditReorderCollectionViewController: UIViewController, } } - func toggleModes() { + @objc func toggleModes() { switch toggle { case .edit: toggle = .reorder diff --git a/components/Cards/examples/EditReorderShapedCollectionViewController.swift b/components/Cards/examples/EditReorderShapedCollectionViewController.swift index d05389520b6..818d58559eb 100644 --- a/components/Cards/examples/EditReorderShapedCollectionViewController.swift +++ b/components/Cards/examples/EditReorderShapedCollectionViewController.swift @@ -92,22 +92,17 @@ class EditReorderShapedCollectionViewController: UIViewController, dataSource.append((i, false)) } - #if swift(>=3.2) - if #available(iOS 11, *) { - let guide = view.safeAreaLayoutGuide - NSLayoutConstraint.activate([ - collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), - collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), - collectionView.topAnchor.constraint(equalTo: view.topAnchor), - collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) - collectionView.contentInsetAdjustmentBehavior = .always - } else { - preiOS11Constraints() - } - #else + if #available(iOS 11, *) { + let guide = view.safeAreaLayoutGuide + NSLayoutConstraint.activate([ + collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), + collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), + collectionView.topAnchor.constraint(equalTo: view.topAnchor), + collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) + collectionView.contentInsetAdjustmentBehavior = .always + } else { preiOS11Constraints() - #endif - + } } func preiOS11Constraints() { @@ -121,7 +116,7 @@ class EditReorderShapedCollectionViewController: UIViewController, views: ["view": collectionView])); } - func toggleModes() { + @objc func toggleModes() { if toggle == .edit { toggle = .reorder navigationItem.rightBarButtonItem?.title = "Reorder" diff --git a/components/Cards/examples/ShapedCardViewController.swift b/components/Cards/examples/ShapedCardViewController.swift index 41f057d704b..616e046823d 100644 --- a/components/Cards/examples/ShapedCardViewController.swift +++ b/components/Cards/examples/ShapedCardViewController.swift @@ -148,7 +148,7 @@ class ShapedCardViewController: UIViewController { secondarySlider.sendActions(for: .valueChanged) } - func didChangeSliderValue(slider: UISlider) { + @objc func didChangeSliderValue(slider: UISlider) { if let shape = card.shapeGenerator as? MDCRectangleShapeGenerator { if slider == primarySlider { let cutCornerTreatment = MDCCutCornerTreatment(cut: CGFloat(slider.value)) @@ -170,7 +170,7 @@ class ShapedCardViewController: UIViewController { return super.traitCollection } - func changeShape() { + @objc func changeShape() { primarySlider.isHidden = true secondarySlider.isHidden = true switch(card.shapeGenerator) { @@ -178,16 +178,16 @@ class ShapedCardViewController: UIViewController { let shapeGenerator = MDCCurvedRectShapeGenerator(cornerSize: CGSize(width: 50, height: 100)) card.shapeGenerator = shapeGenerator - card.contentView.layoutMargins = UIEdgeInsetsMake(0, 40, 0, 40) + card.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40) case is MDCCurvedRectShapeGenerator: let shapeGenerator = MDCPillShapeGenerator() card.shapeGenerator = shapeGenerator - card.contentView.layoutMargins = UIEdgeInsetsMake(0, 80, 0, 80) + card.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 80, bottom: 0, right: 80) case is MDCPillShapeGenerator: let shapeGenerator = MDCSlantedRectShapeGenerator() shapeGenerator.slant = 40 card.shapeGenerator = shapeGenerator - card.contentView.layoutMargins = UIEdgeInsetsMake(0, 40, 0, 40) + card.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40) case is MDCSlantedRectShapeGenerator: fallthrough default: @@ -206,7 +206,7 @@ class ShapedCardViewController: UIViewController { let triangleEdgeTreatment = MDCTriangleEdgeTreatment(size: 0, style: MDCTriangleEdgeStyleCut) shapeGenerator.setEdges(triangleEdgeTreatment) card.shapeGenerator = shapeGenerator - card.contentView.layoutMargins = UIEdgeInsetsMake(0, 5, 0, 5) + card.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) } } diff --git a/components/Cards/examples/supplemental/CardEditReorderCollectionCell.swift b/components/Cards/examples/supplemental/CardEditReorderCollectionCell.swift index 5c5a9c4f34e..85f4690702c 100644 --- a/components/Cards/examples/supplemental/CardEditReorderCollectionCell.swift +++ b/components/Cards/examples/supplemental/CardEditReorderCollectionCell.swift @@ -47,7 +47,8 @@ class CardEditReorderCollectionCell: MDCCardCollectionCell { self.contentView.addSubview(imageView) self.contentView.addSubview(titleLabel) - titleLabel.setContentCompressionResistancePriority(800, for: .vertical) + titleLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 800), + for: .vertical) addConstraints() } diff --git a/components/Cards/tests/unit/Theming/CardsMaterialThemingTests.swift b/components/Cards/tests/unit/Theming/CardsMaterialThemingTests.swift index db961733151..66c1cec2ee6 100644 --- a/components/Cards/tests/unit/Theming/CardsMaterialThemingTests.swift +++ b/components/Cards/tests/unit/Theming/CardsMaterialThemingTests.swift @@ -99,7 +99,7 @@ class CardsMaterialThemingTests: XCTestCase { } // Test remaining properties - [UIControlState.normal, .highlighted, .selected, .disabled].forEach { + [UIControl.State.normal, .highlighted, .selected, .disabled].forEach { XCTAssertEqual(card.shadowElevation(for: $0), ShadowElevation.none, "Shadow elevation incorrect for state \($0)") diff --git a/components/ChipTextField/examples/UITextFieldWithChipsExample.swift b/components/ChipTextField/examples/UITextFieldWithChipsExample.swift index 378f96455fd..b3554bcf6ac 100644 --- a/components/ChipTextField/examples/UITextFieldWithChipsExample.swift +++ b/components/ChipTextField/examples/UITextFieldWithChipsExample.swift @@ -119,7 +119,7 @@ class UITextFieldWithChipsExample: UIViewController { //lastmax = lastLabel.frame.maxX } else { leadingConstraint = label.leadingAnchor.constraint(equalTo: leftView.leadingAnchor) - leadingConstraint?.priority = UILayoutPriorityDefaultLow + leadingConstraint?.priority = UILayoutPriority.defaultLow leadingConstraint?.isActive = true } } else { @@ -222,7 +222,7 @@ private class InsetTextField: UITextField { // text bounds override func textRect(forBounds bounds: CGRect) -> CGRect { let superbounds = super.textRect(forBounds: bounds) - var newbounds = UIEdgeInsetsInsetRect(superbounds, insetRect) + var newbounds = superbounds.inset(by: insetRect) newbounds.origin.x = insetX return newbounds } @@ -230,7 +230,7 @@ private class InsetTextField: UITextField { // text bounds while editing override func editingRect(forBounds bounds: CGRect) -> CGRect { let superbounds = super.editingRect(forBounds: bounds) - var newbounds = UIEdgeInsetsInsetRect(superbounds, insetRect) + var newbounds = superbounds.inset(by: insetRect) newbounds.origin.x = insetX return newbounds } @@ -252,14 +252,14 @@ class PlainTextField: UITextField { // text bounds override func textRect(forBounds bounds: CGRect) -> CGRect { let superbounds = super.textRect(forBounds: bounds) - let newbounds = UIEdgeInsetsInsetRect(superbounds, insetRect) + let newbounds = superbounds.inset(by: insetRect) return newbounds } // text bounds while editing override func editingRect(forBounds bounds: CGRect) -> CGRect { let superbounds = super.editingRect(forBounds: bounds) - let newbounds = UIEdgeInsetsInsetRect(superbounds, insetRect) + let newbounds = superbounds.inset(by: insetRect) return newbounds } } diff --git a/components/Chips/BUILD b/components/Chips/BUILD index 8cf98b32e39..b48ae492bd6 100644 --- a/components/Chips/BUILD +++ b/components/Chips/BUILD @@ -152,7 +152,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/Chips/examples/ChipsFieldDeleteEnabledViewController.swift b/components/Chips/examples/ChipsFieldDeleteEnabledViewController.swift index c563be42378..a47461c4288 100644 --- a/components/Chips/examples/ChipsFieldDeleteEnabledViewController.swift +++ b/components/Chips/examples/ChipsFieldDeleteEnabledViewController.swift @@ -49,7 +49,7 @@ class ChipsFieldDeleteEnabledViewController : UIViewController, MDCChipFieldDele var frame = view.bounds if #available(iOS 11.0, *) { - frame = UIEdgeInsetsInsetRect(frame, view.safeAreaInsets) + frame = frame.inset(by: view.safeAreaInsets) } frame.size = chipField.sizeThatFits(frame.size) chipField.frame = frame @@ -63,7 +63,7 @@ class ChipsFieldDeleteEnabledViewController : UIViewController, MDCChipFieldDele chip.applyTheme(withScheme: containerScheming) chip.sizeToFit() let chipVerticalInset = min(0, chip.bounds.height - 48 / 2) - chip.hitAreaInsets = UIEdgeInsetsMake(chipVerticalInset, 0, chipVerticalInset, 0) + chip.hitAreaInsets = UIEdgeInsets(top: chipVerticalInset, left: 0, bottom: chipVerticalInset, right: 0) } } // MARK - Catalog by Convention diff --git a/components/Dialogs/BUILD b/components/Dialogs/BUILD index 56511db01e1..780ae839fee 100644 --- a/components/Dialogs/BUILD +++ b/components/Dialogs/BUILD @@ -164,7 +164,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/Dialogs/examples/DialogsAlertComparisonExample.swift b/components/Dialogs/examples/DialogsAlertComparisonExample.swift index 3a9e328461f..818f9b88b73 100644 --- a/components/Dialogs/examples/DialogsAlertComparisonExample.swift +++ b/components/Dialogs/examples/DialogsAlertComparisonExample.swift @@ -87,7 +87,7 @@ class DialogsAlertComparisonExample: UIViewController { ]) uikitButton.translatesAutoresizingMaskIntoConstraints = false - uikitButton.setTitle("UIKit Alert", for: UIControlState()) + uikitButton.setTitle("UIKit Alert", for: UIControl.State()) uikitButton.setTitleColor(UIColor(white: 0.1, alpha:1), for: .normal) uikitButton.sizeToFit() uikitButton.addTarget(self, action: #selector(tapUIKit), for: .touchUpInside) diff --git a/components/Dialogs/examples/DialogsCustomShadowExampleViewController.swift b/components/Dialogs/examples/DialogsCustomShadowExampleViewController.swift index 0599c650226..a0ae14fb6b5 100644 --- a/components/Dialogs/examples/DialogsCustomShadowExampleViewController.swift +++ b/components/Dialogs/examples/DialogsCustomShadowExampleViewController.swift @@ -70,8 +70,8 @@ class DialogsCustomShadowExampleViewController: UIViewController { view.backgroundColor = containerScheme.colorScheme.backgroundColor - textButton.setTitle("PRESENT ALERT", for: UIControlState()) - textButton.setTitleColor(UIColor(white: 0.1, alpha:1), for: UIControlState()) + textButton.setTitle("PRESENT ALERT", for: UIControl.State()) + textButton.setTitleColor(UIColor(white: 0.1, alpha:1), for: UIControl.State()) textButton.sizeToFit() textButton.translatesAutoresizingMaskIntoConstraints = false textButton.addTarget(self, action: #selector(tap), for: .touchUpInside) diff --git a/components/Dialogs/examples/DialogsLongAlertExampleViewController.swift b/components/Dialogs/examples/DialogsLongAlertExampleViewController.swift index 67675b8bc5d..c21f1d4c5d7 100644 --- a/components/Dialogs/examples/DialogsLongAlertExampleViewController.swift +++ b/components/Dialogs/examples/DialogsLongAlertExampleViewController.swift @@ -30,8 +30,8 @@ class DialogsLongAlertExampleViewController: UIViewController { view.backgroundColor = containerScheme.colorScheme.backgroundColor - textButton.setTitle("PRESENT ALERT", for: UIControlState()) - textButton.setTitleColor(UIColor(white: 0.1, alpha:1), for: UIControlState()) + textButton.setTitle("PRESENT ALERT", for: UIControl.State()) + textButton.setTitleColor(UIColor(white: 0.1, alpha:1), for: UIControl.State()) textButton.sizeToFit() textButton.translatesAutoresizingMaskIntoConstraints = false textButton.addTarget(self, action: #selector(tap), for: .touchUpInside) diff --git a/components/FeatureHighlight/examples/FeatureHightlightTypicalUseViewController.swift b/components/FeatureHighlight/examples/FeatureHightlightTypicalUseViewController.swift index e1a36e7fb7d..1350aca0dec 100644 --- a/components/FeatureHighlight/examples/FeatureHightlightTypicalUseViewController.swift +++ b/components/FeatureHighlight/examples/FeatureHightlightTypicalUseViewController.swift @@ -56,7 +56,7 @@ class FeatureHighlightSwiftViewController: UIViewController { featureButton.frame.origin.y = view.bounds.height / 2 - featureButton.frame.height / 2 } - func showFeatureHighlight() { + @objc func showFeatureHighlight() { let vc = MDCFeatureHighlightViewController(highlightedView: featureButton, completion: nil) MDCFeatureHighlightColorThemer.applySemanticColorScheme(colorScheme, to: vc) diff --git a/components/FlexibleHeader/BUILD b/components/FlexibleHeader/BUILD index a00a800e8f2..873cd9b4633 100644 --- a/components/FlexibleHeader/BUILD +++ b/components/FlexibleHeader/BUILD @@ -83,7 +83,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue176Tests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue176Tests.swift index 358dece1ce4..d7907b685a2 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue176Tests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue176Tests.swift @@ -37,11 +37,7 @@ class FlexibleHeaderControllerIssue176Tests: XCTestCase { } func registerToParentViewController(_ parent: UIViewController) { - #if swift(>=4.2) - parent.addChild(fhvc) - #else - parent.addChildViewController(fhvc) - #endif + parent.addChild(fhvc) parent.view.addSubview(fhvc.view) } @@ -50,11 +46,7 @@ class FlexibleHeaderControllerIssue176Tests: XCTestCase { self.registerToParentViewController(parentVc) // NOTE: No tracking scroll view - #if swift(>=4.2) fhvc.didMove(toParent: parentVc) - #else - fhvc.didMove(toParentViewController: parentVc) - #endif XCTAssertEqual(fhvc.view.bounds.size.height, fhvc.headerView.minimumHeight) } @@ -71,11 +63,7 @@ class FlexibleHeaderControllerIssue176Tests: XCTestCase { fhvc.headerView.trackingScrollView = parentVc.tableView - #if swift(>=4.2) fhvc.didMove(toParent: parentVc) - #else - fhvc.didMove(toParentViewController: parentVc) - #endif XCTAssertEqual(fhvc.headerView.trackingScrollView!.contentOffset.y, -fhvc.headerView.maximumHeight) diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue279Tests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue279Tests.swift index 39e9d20f28b..c6dfe82e759 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue279Tests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderControllerIssue279Tests.swift @@ -30,20 +30,12 @@ class FlexibleHeaderControllerIssue279Tests: XCTestCase { fhvc = MDCFlexibleHeaderViewController() tableViewController = UITableViewController() - #if swift(>=4.2) tableViewController.addChild(fhvc) - #else - tableViewController.addChildViewController(fhvc) - #endif tableViewController.view.addSubview(fhvc.headerView) fhvc.headerView.trackingScrollView = tableViewController.tableView - #if swift(>=4.2) fhvc.didMove(toParent: tableViewController) - #else - fhvc.didMove(toParentViewController: tableViewController) - #endif } override func tearDown() { diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionLegacyTopLayoutGuideTests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionLegacyTopLayoutGuideTests.swift index 24703080be9..f2030b6e317 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionLegacyTopLayoutGuideTests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionLegacyTopLayoutGuideTests.swift @@ -42,25 +42,15 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { func testNoScrollViewTopLayoutGuideEqualsZero() { // Given let contentViewController = UIViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) } - #endif } // MARK: Untracked table view @@ -68,26 +58,16 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { func testUntrackedTableViewTopLayoutGuideEqualsZero() { // Given let contentViewController = UITableViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked table view @@ -96,28 +76,18 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { // Given let contentViewController = UITableViewController() fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } func testTrackedTableViewTopLayoutGuideEqualsBottomEdgeOfHeaderViewAfterScrolling() { @@ -127,17 +97,9 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { CGSize(width: contentViewController.tableView.bounds.width, height: contentViewController.tableView.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() contentViewController.tableView.contentOffset = CGPoint(x: 0, y: -contentViewController.tableView.contentInset.top) @@ -146,13 +108,11 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Untracked collection view @@ -161,26 +121,16 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { // Given let flow = UICollectionViewFlowLayout() let contentViewController = UICollectionViewController(collectionViewLayout: flow) - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view view @@ -190,28 +140,18 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { let flow = UICollectionViewFlowLayout() let contentViewController = UICollectionViewController(collectionViewLayout: flow) fhvc.headerView.trackingScrollView = contentViewController.collectionView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } func testTrackedCollectionViewTopLayoutGuideEqualsZeroAfterScrolling() { @@ -222,17 +162,9 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { CGSize(width: contentViewController.collectionView!.bounds.width, height: contentViewController.collectionView!.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.collectionView! - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() contentViewController.collectionView!.contentOffset = CGPoint(x: 0, y: -contentViewController.collectionView!.contentInset.top) @@ -240,13 +172,11 @@ class FlexibleHeaderInjectionLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } } diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionTopLayoutGuideTests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionTopLayoutGuideTests.swift index e029dc3e7aa..0b873a3c2c8 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionTopLayoutGuideTests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderInjectionTopLayoutGuideTests.swift @@ -40,27 +40,17 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { func testTopLayoutGuideIsUnaffactedWithNoTopLayoutGuideViewController() { // Given let contentViewController = UIViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.isTopLayoutGuideAdjustmentEnabled = true fhvc.topLayoutGuideViewController = nil - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) } - #endif } // MARK: No scroll view @@ -68,27 +58,17 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { func testNoScrollViewTopLayoutGuideEqualsBottomEdgeOfHeaderView() { // Given let contentViewController = UIViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, fhvc.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Untracked table view @@ -96,68 +76,46 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { func testUntrackedTableViewTopLayoutGuideEqualsBottomEdgeOfHeaderView() { // Given let contentViewController = UITableViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, fhvc.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } func testTrackingAnUntrackedTableViewTopLayoutGuideEqualsBottomEdgeOfHeaderView() { // Given let contentViewController = UITableViewController() - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, fhvc.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif // And then when fhvc.headerView.trackingScrollView = contentViewController.tableView // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Tracked table view @@ -166,29 +124,19 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { // Given let contentViewController = UITableViewController() fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } func testTrackedTableViewTopLayoutGuideEqualsBottomEdgeOfHeaderViewAfterScrolling() { @@ -198,18 +146,10 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { CGSize(width: contentViewController.tableView.bounds.width, height: contentViewController.tableView.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() contentViewController.tableView.contentOffset = CGPoint(x: 0, y: -contentViewController.tableView.contentInset.top) @@ -218,13 +158,11 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } // MARK: Untracked collection view @@ -233,28 +171,18 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { // Given let flow = UICollectionViewFlowLayout() let contentViewController = UICollectionViewController(collectionViewLayout: flow) - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, fhvc.headerView.frame.maxY - MDCDeviceTopSafeAreaInset()) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view view @@ -264,29 +192,19 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { let flow = UICollectionViewFlowLayout() let contentViewController = UICollectionViewController(collectionViewLayout: flow) fhvc.headerView.trackingScrollView = contentViewController.collectionView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } func testTrackedCollectionViewTopLayoutGuideEqualsBottomEdgeOfHeaderViewAfterScrolling() { @@ -297,18 +215,10 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { CGSize(width: contentViewController.collectionView!.bounds.width, height: contentViewController.collectionView!.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.collectionView! - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) fhvc.topLayoutGuideViewController = contentViewController - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif fhvc.headerView.trackingScrollDidScroll() contentViewController.collectionView!.contentOffset = CGPoint(x: 0, y: -contentViewController.collectionView!.contentInset.top) @@ -316,13 +226,11 @@ class FlexibleHeaderInjectionTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, fhvc.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, fhvc.headerView.maximumHeight + MDCDeviceTopSafeAreaInset()) } - #endif } } diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderScrollViewObservationTests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderScrollViewObservationTests.swift index 64d595608e3..28423a467d3 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderScrollViewObservationTests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderScrollViewObservationTests.swift @@ -43,17 +43,9 @@ class FlexibleHeaderScrollViewObservationTests: XCTestCase { CGSize(width: contentViewController.tableView.bounds.width, height: contentViewController.tableView.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // When let overshoot: CGFloat = 10 @@ -75,19 +67,11 @@ class FlexibleHeaderScrollViewObservationTests: XCTestCase { height: contentViewController.tableView.bounds.height * 2) fhvc.headerView.trackingScrollView = contentViewController.tableView - #if swift(>=4.2) contentViewController.addChild(fhvc) - #else - contentViewController.addChildViewController(fhvc) - #endif contentViewController.view.addSubview(fhvc.view) - #if swift(>=4.2) fhvc.didMove(toParent: contentViewController) - #else - fhvc.didMove(toParentViewController: contentViewController) - #endif // When let scrollAmount: CGFloat = fhvc.headerView.maximumHeight diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingLegacyTopLayoutGuideTests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingLegacyTopLayoutGuideTests.swift index 671becef1fe..79ba7f69540 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingLegacyTopLayoutGuideTests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingLegacyTopLayoutGuideTests.swift @@ -47,11 +47,9 @@ class FlexibleHeaderWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) } - #endif } // MARK: Untracked table view @@ -64,12 +62,10 @@ class FlexibleHeaderWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked table view @@ -84,13 +80,11 @@ class FlexibleHeaderWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, container.headerViewController.headerView.maximumHeight) } - #endif } // MARK: Untracked collection view @@ -104,12 +98,10 @@ class FlexibleHeaderWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view view @@ -126,13 +118,11 @@ class FlexibleHeaderWrappingLegacyTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, 0) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, container.headerViewController.headerView.maximumHeight) } - #endif } } diff --git a/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingTopLayoutGuideTests.swift b/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingTopLayoutGuideTests.swift index 4fec05bb5fb..365eb6673bd 100644 --- a/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingTopLayoutGuideTests.swift +++ b/components/FlexibleHeader/tests/unit/FlexibleHeaderWrappingTopLayoutGuideTests.swift @@ -48,12 +48,10 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.headerViewController.headerView.frame.maxY) } - #endif } func testEarlyViewLoadStillAffectsTopLayoutGuide() { @@ -67,12 +65,10 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.headerViewController.headerView.frame.maxY) } - #endif } // MARK: Untracked table view @@ -88,13 +84,11 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.headerViewController.headerView.frame.maxY) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked table view @@ -110,13 +104,11 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { // Then XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.tableView.adjustedContentInset.top, container.headerViewController.headerView.maximumHeight) } - #endif } // MARK: Untracked collection view @@ -133,13 +125,11 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, container.headerViewController.headerView.frame.maxY) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, 0) } - #endif } // MARK: Tracked collection view view @@ -159,13 +149,11 @@ class FlexibleHeaderWrappingTopLayoutGuideTests: XCTestCase { XCTAssertEqual(contentViewController.view.frame, container.view.bounds) XCTAssertEqual(contentViewController.topLayoutGuide.length, container.headerViewController.headerView.frame.maxY) - #if swift(>=3.2) if #available(iOS 11.0, *) { XCTAssertEqual(contentViewController.additionalSafeAreaInsets.top, 0) XCTAssertEqual(contentViewController.collectionView!.adjustedContentInset.top, container.headerViewController.headerView.maximumHeight) } - #endif } } diff --git a/components/LibraryInfo/BUILD b/components/LibraryInfo/BUILD index ea434f0f09c..8f3a7a7fec5 100644 --- a/components/LibraryInfo/BUILD +++ b/components/LibraryInfo/BUILD @@ -35,7 +35,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [":LibraryInfo"], diff --git a/components/List/examples/BaseCellExample.swift b/components/List/examples/BaseCellExample.swift index e45e55ff59f..9eef3617f76 100644 --- a/components/List/examples/BaseCellExample.swift +++ b/components/List/examples/BaseCellExample.swift @@ -64,14 +64,12 @@ class BaseCellExample : UIViewController { var width = view.bounds.size.width var height = view.bounds.size.height - #if swift(>=3.2) if #available(iOS 11.0, *) { originX += view.safeAreaInsets.left originY += view.safeAreaInsets.top width -= (view.safeAreaInsets.left + view.safeAreaInsets.right) height -= (view.safeAreaInsets.top + view.safeAreaInsets.bottom) } - #endif let frame = CGRect(x: originX, y: originY, width: width, height: height); collectionView.frame = frame diff --git a/components/MaskedTransition/BUILD b/components/MaskedTransition/BUILD index 1fa040c63f2..a99a992bb5e 100644 --- a/components/MaskedTransition/BUILD +++ b/components/MaskedTransition/BUILD @@ -67,7 +67,7 @@ swift_library( srcs = native.glob(["examples/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], deps = [ ":MaskedTransition", diff --git a/components/MaskedTransition/examples/MaskedTransitionTypicalUse.swift b/components/MaskedTransition/examples/MaskedTransitionTypicalUse.swift index 518d15f7a7c..dc859ee425d 100644 --- a/components/MaskedTransition/examples/MaskedTransitionTypicalUse.swift +++ b/components/MaskedTransition/examples/MaskedTransitionTypicalUse.swift @@ -23,7 +23,7 @@ open class MaskedTransitionTypicalUseSwiftExample: UIViewController { let name: String let viewControllerType: UIViewController.Type let calculateFrame: ((UIPresentationController) -> CGRect)? - let autoresizingMask: UIViewAutoresizing + let autoresizingMask: UIView.AutoresizingMask let useSafeAreaInsets: Bool } var targets: [TargetInfo] = [] @@ -118,7 +118,7 @@ open class MaskedTransitionTypicalUseSwiftExample: UIViewController { } var transitionController: MDCMaskedTransitionController? = nil - func didTapFab(fab: UIView) { + @objc func didTapFab(fab: UIView) { guard let indexPathForSelectedRow = tableView.indexPathForSelectedRow else { return } let target = targets[indexPathForSelectedRow.row] let vc = target.viewControllerType.init() @@ -169,7 +169,7 @@ private class ToolbarViewController: UIViewController { view.addSubview(toolbar) } - func didTap() { + @objc func didTap() { dismiss(animated: true) } } @@ -238,7 +238,7 @@ private class ModalViewController: UIViewController { constant: bottomOffset).isActive = true } - func didTap() { + @objc func didTap() { dismiss(animated: true) } } diff --git a/components/NavigationBar/BUILD b/components/NavigationBar/BUILD index 42ddefb5699..ef431736ab4 100644 --- a/components/NavigationBar/BUILD +++ b/components/NavigationBar/BUILD @@ -108,7 +108,7 @@ swift_library( srcs = native.glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/NavigationBar/examples/NavigationBarTypicalUseExample.swift b/components/NavigationBar/examples/NavigationBarTypicalUseExample.swift index 96863995815..e3f0f7384a6 100644 --- a/components/NavigationBar/examples/NavigationBarTypicalUseExample.swift +++ b/components/NavigationBar/examples/NavigationBarTypicalUseExample.swift @@ -40,19 +40,9 @@ open class NavigationBarTypicalUseSwiftExample: UIViewController { navBar.translatesAutoresizingMaskIntoConstraints = false - #if swift(>=3.2) - if #available(iOS 11.0, *) { - self.view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: self.navBar.topAnchor).isActive = true - } else { - NSLayoutConstraint(item: self.topLayoutGuide, - attribute: .bottom, - relatedBy: .equal, - toItem: self.navBar, - attribute: .top, - multiplier: 1, - constant: 0).isActive = true - } - #else + if #available(iOS 11.0, *) { + self.view.safeAreaLayoutGuide.topAnchor.constraint(equalTo: self.navBar.topAnchor).isActive = true + } else { NSLayoutConstraint(item: self.topLayoutGuide, attribute: .bottom, relatedBy: .equal, @@ -60,7 +50,7 @@ open class NavigationBarTypicalUseSwiftExample: UIViewController { attribute: .top, multiplier: 1, constant: 0).isActive = true - #endif + } let viewBindings = ["navBar": navBar] @@ -140,14 +130,14 @@ class ExampleInstructionsViewNavigationBarTypicalUseSwift: UIView { style.alignment = .center style.lineBreakMode = .byWordWrapping let instructionsDictionary1 = [ - NSFontAttributeName : UIFont.preferredFont(forTextStyle: .headline), - NSForegroundColorAttributeName : MDCPalette.grey.tint600.withAlphaComponent(0.87), - NSParagraphStyleAttributeName : style + NSAttributedString.Key.font : UIFont.preferredFont(forTextStyle: .headline), + NSAttributedString.Key.foregroundColor : MDCPalette.grey.tint600.withAlphaComponent(0.87), + NSAttributedString.Key.paragraphStyle : style ] let instructionsDictionary2 = [ - NSFontAttributeName : UIFont.preferredFont(forTextStyle: .subheadline), - NSForegroundColorAttributeName : MDCPalette.grey.tint600.withAlphaComponent(0.87), - NSParagraphStyleAttributeName : style + NSAttributedString.Key.font : UIFont.preferredFont(forTextStyle: .subheadline), + NSAttributedString.Key.foregroundColor : MDCPalette.grey.tint600.withAlphaComponent(0.87), + NSAttributedString.Key.paragraphStyle : style ] let instructionText = "SWIPE RIGHT\n\n\nfrom left edge to go back\n\n\n\n\n" let instructionsAttributedString = NSMutableAttributedString(string: instructionText) diff --git a/components/NavigationBar/tests/unit/NavigationBarAccessibilityMutatorTestColorTest.swift b/components/NavigationBar/tests/unit/NavigationBarAccessibilityMutatorTestColorTest.swift index 26a095fb01f..1d6cbbbff6b 100644 --- a/components/NavigationBar/tests/unit/NavigationBarAccessibilityMutatorTestColorTest.swift +++ b/components/NavigationBar/tests/unit/NavigationBarAccessibilityMutatorTestColorTest.swift @@ -46,7 +46,7 @@ class NavigationBarAccessibilityMutatorTestColorTest: XCTestCase { mutator.mutate(navBar) // Then - let fontColor = navBar.titleTextAttributes![NSForegroundColorAttributeName] as! UIColor + let fontColor = navBar.titleTextAttributes![NSAttributedString.Key.foregroundColor] as! UIColor let tintColor = navBar.tintColor let accessibleColor = MDFTextAccessibility.textColor(onBackgroundColor: UIColor.black, targetTextAlpha: 1.0, @@ -64,7 +64,7 @@ class NavigationBarAccessibilityMutatorTestColorTest: XCTestCase { mutator.mutate(navBar) // Then - let fontColor = navBar.titleTextAttributes![NSForegroundColorAttributeName] as! UIColor + let fontColor = navBar.titleTextAttributes![NSAttributedString.Key.foregroundColor] as! UIColor let tintColor = navBar.tintColor let accessibleColor = MDFTextAccessibility.textColor(onBackgroundColor: UIColor.white, targetTextAlpha: 1.0, @@ -75,14 +75,16 @@ class NavigationBarAccessibilityMutatorTestColorTest: XCTestCase { func testNoBackgroundColor() { // Given no background color set - let fontColorBefore = navBar.titleTextAttributes?[NSForegroundColorAttributeName] as? UIColor + let fontColorBefore = navBar.titleTextAttributes?[NSAttributedString.Key.foregroundColor] + as? UIColor let tintColorBefore = navBar.tintColor // When mutator.mutate(navBar) // Then - let fontColorAfter = navBar.titleTextAttributes?[NSForegroundColorAttributeName] as? UIColor + let fontColorAfter = navBar.titleTextAttributes?[NSAttributedString.Key.foregroundColor] + as? UIColor let tintColorAfter = navBar.tintColor XCTAssertEqual(fontColorBefore, fontColorAfter) XCTAssertEqual(tintColorBefore, tintColorAfter) diff --git a/components/NavigationDrawer/examples/BottomDrawerWithChangingContentSize.swift b/components/NavigationDrawer/examples/BottomDrawerWithChangingContentSize.swift index d4d0fbe4a9a..27449491ff5 100644 --- a/components/NavigationDrawer/examples/BottomDrawerWithChangingContentSize.swift +++ b/components/NavigationDrawer/examples/BottomDrawerWithChangingContentSize.swift @@ -143,7 +143,7 @@ UICollectionViewDelegate, UICollectionViewDataSource { return 1 } - func didTap(gestureRecognizer : UITapGestureRecognizer) { + @objc func didTap(gestureRecognizer : UITapGestureRecognizer) { longList = !longList collectionView.reloadData() self.preferredContentSize = CGSize(width: self.view.bounds.width, diff --git a/components/NavigationDrawer/examples/BottomDrawerWithHeaderExample.swift b/components/NavigationDrawer/examples/BottomDrawerWithHeaderExample.swift index 6c52a95dfa1..977b76787e8 100644 --- a/components/NavigationDrawer/examples/BottomDrawerWithHeaderExample.swift +++ b/components/NavigationDrawer/examples/BottomDrawerWithHeaderExample.swift @@ -86,7 +86,7 @@ class BottomDrawerWithHeaderExample: UIViewController, MDCBottomDrawerViewContro extension BottomDrawerWithHeaderExample { - class func catalogMetadata() -> [String: Any] { + @objc class func catalogMetadata() -> [String: Any] { return [ "breadcrumbs": ["Navigation Drawer", "Bottom Drawer"], "primaryDemo": false, diff --git a/components/PageControl/examples/PageControlTypicalUseExample.swift b/components/PageControl/examples/PageControlTypicalUseExample.swift index d769c9ed3bb..2c7b13047ec 100644 --- a/components/PageControl/examples/PageControlTypicalUseExample.swift +++ b/components/PageControl/examples/PageControlTypicalUseExample.swift @@ -86,11 +86,9 @@ class PageControlSwiftExampleViewController: UIViewController, UIScrollViewDeleg scrollView.contentOffset = offset var edgeInsets = UIEdgeInsets.zero; - #if swift(>=3.2) - if #available(iOS 11, *) { - edgeInsets = self.view.safeAreaInsets - } - #endif + if #available(iOS 11, *) { + edgeInsets = self.view.safeAreaInsets + } let pageControlSize = pageControl.sizeThatFits(view.bounds.size) let yOffset = self.view.bounds.height - pageControlSize.height - 8 - edgeInsets.bottom; pageControl.frame = diff --git a/components/Palettes/BUILD b/components/Palettes/BUILD index 3e975d7b2ca..6021ae230a7 100644 --- a/components/Palettes/BUILD +++ b/components/Palettes/BUILD @@ -32,7 +32,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [":Palettes"], diff --git a/components/Palettes/examples/supplemental/PalettesExampleViewController.swift b/components/Palettes/examples/supplemental/PalettesExampleViewController.swift index 156960aa04e..c592853ea50 100644 --- a/components/Palettes/examples/supplemental/PalettesExampleViewController.swift +++ b/components/Palettes/examples/supplemental/PalettesExampleViewController.swift @@ -60,7 +60,7 @@ class PalettesExampleViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() self.tableView.separatorStyle = .none - self.tableView.rowHeight = UITableViewAutomaticDimension + self.tableView.rowHeight = UITableView.automaticDimension self.tableView.estimatedRowHeight = 50 } @@ -109,7 +109,7 @@ class PalettesExampleViewController: UITableViewController { self.init(style: .grouped) } - override init(style: UITableViewStyle) { + override init(style: UITableView.Style) { super.init(style: style) } diff --git a/components/Ripple/examples/CardCellsWithRippleExample.swift b/components/Ripple/examples/CardCellsWithRippleExample.swift index f30e34572a9..dc242a9c496 100644 --- a/components/Ripple/examples/CardCellsWithRippleExample.swift +++ b/components/Ripple/examples/CardCellsWithRippleExample.swift @@ -76,21 +76,17 @@ class CardCellsWithRippleExample: UIViewController, collectionView.addGestureRecognizer(longPressGesture) } - #if swift(>=3.2) - if #available(iOS 11, *) { - let guide = view.safeAreaLayoutGuide - NSLayoutConstraint.activate([ - collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), - collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), - collectionView.topAnchor.constraint(equalTo: view.topAnchor), - collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) - collectionView.contentInsetAdjustmentBehavior = .always - } else { - preiOS11Constraints() - } - #else + if #available(iOS 11, *) { + let guide = view.safeAreaLayoutGuide + NSLayoutConstraint.activate([ + collectionView.leftAnchor.constraint(equalTo: guide.leftAnchor), + collectionView.rightAnchor.constraint(equalTo: guide.rightAnchor), + collectionView.topAnchor.constraint(equalTo: view.topAnchor), + collectionView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)]) + collectionView.contentInsetAdjustmentBehavior = .always + } else { preiOS11Constraints() - #endif + } self.updateTitle() } @@ -117,7 +113,7 @@ class CardCellsWithRippleExample: UIViewController, } } - func toggleModes() { + @objc func toggleModes() { switch toggle { case .edit: toggle = .reorder diff --git a/components/ShadowElevations/examples/ShadowElevationsTypicalUseExample.swift b/components/ShadowElevations/examples/ShadowElevationsTypicalUseExample.swift index ae5a5a8d1e3..3bcd7f0b041 100644 --- a/components/ShadowElevations/examples/ShadowElevationsTypicalUseExample.swift +++ b/components/ShadowElevations/examples/ShadowElevationsTypicalUseExample.swift @@ -47,12 +47,13 @@ class ShadowElevationsTypicalUseExample: UIViewController { super.init(nibName: nil, bundle: nil) self.title = "Shadow Elevations (Swift)" - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) let color = UIColor(white: 0.2, alpha:1) appBarViewController.headerView.backgroundColor = color appBarViewController.navigationBar.tintColor = .white - appBarViewController.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white] + appBarViewController.navigationBar.titleTextAttributes = + [NSAttributedString.Key.foregroundColor : UIColor.white] let paperDim = CGFloat(200) paper.frame = @@ -70,7 +71,7 @@ class ShadowElevationsTypicalUseExample: UIViewController { super.viewDidLoad() view.addSubview(appBarViewController.view) - appBarViewController.didMove(toParentViewController: self) + appBarViewController.didMove(toParent: self) } override func viewWillAppear(_ animated: Bool) { diff --git a/components/Snackbar/BUILD b/components/Snackbar/BUILD index fa5d20f24dc..66e847d469e 100644 --- a/components/Snackbar/BUILD +++ b/components/Snackbar/BUILD @@ -111,7 +111,7 @@ swift_library( srcs = glob(["tests/unit/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.swift b/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.swift index 24619559e40..8a21235cb9d 100644 --- a/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.swift +++ b/components/Tabs/examples/supplemental/TabBarIconExampleSupplemental.swift @@ -61,7 +61,7 @@ extension TabBarIconSwiftExample { func setupAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) appBarViewController.headerView.minMaxHeightIncludesSafeArea = false appBarViewController.headerView.minimumHeight = 56 + 72 appBarViewController.headerView.tintColor = MDCPalette.blue.tint500 @@ -77,7 +77,7 @@ extension TabBarIconSwiftExample { view.backgroundColor = UIColor.white view.addSubview(appBarViewController.view) - appBarViewController.didMove(toParentViewController: self) + appBarViewController.didMove(toParent: self) let badgeIncrementItem = UIBarButtonItem(title: "Add", style: .plain, @@ -233,7 +233,7 @@ extension TabBarIconSwiftExample { } extension TabBarIconSwiftExample { - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } diff --git a/components/Tabs/examples/supplemental/TabBarIndicatorTemplateExampleSupplemental.swift b/components/Tabs/examples/supplemental/TabBarIndicatorTemplateExampleSupplemental.swift index 78bc89606be..8880e6bc338 100644 --- a/components/Tabs/examples/supplemental/TabBarIndicatorTemplateExampleSupplemental.swift +++ b/components/Tabs/examples/supplemental/TabBarIndicatorTemplateExampleSupplemental.swift @@ -44,7 +44,7 @@ extension TabBarIndicatorTemplateExample { func makeAppBar() -> MDCAppBarViewController { let appBarViewController = MDCAppBarViewController() - self.addChildViewController(appBarViewController) + self.addChild(appBarViewController) // Give the tab bar enough height to accomodate all possible item appearances. appBarViewController.headerView.minMaxHeightIncludesSafeArea = false @@ -58,7 +58,7 @@ extension TabBarIndicatorTemplateExample { func setupExampleViews() { view.backgroundColor = UIColor.white view.addSubview(appBarViewController.view) - appBarViewController.didMove(toParentViewController: self) + appBarViewController.didMove(toParent: self) // Set up buttons alignmentButton.translatesAutoresizingMaskIntoConstraints = false @@ -68,15 +68,11 @@ extension TabBarIndicatorTemplateExample { // Buttons are laid out relative to the safe area, if available. let alignmentGuide: Any - #if swift(>=3.2) - if #available(iOS 11.0, *) { - alignmentGuide = view.safeAreaLayoutGuide - } else { - alignmentGuide = view - } - #else + if #available(iOS 11.0, *) { + alignmentGuide = view.safeAreaLayoutGuide + } else { alignmentGuide = view - #endif + } NSLayoutConstraint.activate([ // Center alignment button @@ -117,7 +113,7 @@ extension TabBarIndicatorTemplateExample { } extension TabBarIndicatorTemplateExample { - override var childViewControllerForStatusBarStyle: UIViewController? { + override var childForStatusBarStyle: UIViewController? { return appBarViewController } } diff --git a/components/TextFields/BUILD b/components/TextFields/BUILD index 1b5aca21c67..8de3b677224 100644 --- a/components/TextFields/BUILD +++ b/components/TextFields/BUILD @@ -127,7 +127,7 @@ swift_library( srcs = glob(["examples/experimental/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], deps = [":ExperimentalExampleSource"], ) @@ -196,7 +196,7 @@ swift_library( ]), copts = [ "-swift-version", - "3", + "4.2", ], visibility = ["//visibility:private"], deps = [ diff --git a/components/TextFields/examples/TextFieldFilledExample.swift b/components/TextFields/examples/TextFieldFilledExample.swift index b5dcb9598a0..3db844e04c4 100644 --- a/components/TextFields/examples/TextFieldFilledExample.swift +++ b/components/TextFields/examples/TextFieldFilledExample.swift @@ -178,15 +178,11 @@ final class TextFieldFilledSwiftExample: UIViewController { scrollView.addSubview(message) let messageController = MDCTextInputControllerFilled(textInput: message) message.textView?.delegate = self - #if swift(>=3.2) - message.text = """ - This is where you could put a multi-line message like an email. - - It can even handle new lines. - """ - #else - message.text = "This is where you could put a multi-line message like an email.\n\nIt can even handle new lines." - #endif + message.text = """ + This is where you could put a multi-line message like an email. + + It can even handle new lines. + """ messageController.placeholderText = "Message" allTextFieldControllers.append(messageController) @@ -228,39 +224,22 @@ final class TextFieldFilledSwiftExample: UIViewController { options: [], metrics: nil, views: views) - #if swift(>=3.2) - if #available(iOS 11.0, *) { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } else { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } - #else + if #available(iOS 11.0, *) { + constraints += [NSLayoutConstraint(item: name, + attribute: .top, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .top, + multiplier: 1, + constant: 20), + NSLayoutConstraint(item: message, + attribute: .bottom, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .bottomMargin, + multiplier: 1, + constant: -20)] + } else { constraints += [NSLayoutConstraint(item: name, attribute: .top, relatedBy: .equal, @@ -275,7 +254,7 @@ final class TextFieldFilledSwiftExample: UIViewController { attribute: .bottomMargin, multiplier: 1, constant: -20)] - #endif + } let stateZipViews = [ "state": state, "zip": zip ] constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[state(80)]-[zip]|", @@ -361,14 +340,15 @@ extension TextFieldFilledSwiftExample: UITextFieldDelegate { if textField == state { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters.inverted), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { stateController.setErrorText("Error: State can only contain letters", errorAccessibilityValue: nil) } else { stateController.setErrorText(nil, errorAccessibilityValue: nil) } - } else if textField == zip { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), - fullString[range].characterCount > 0 { + } else if textField == zip { + if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), + String(fullString[range]).characterCount > 0 { zipController.setErrorText("Error: Zip can only contain numbers", errorAccessibilityValue: nil) } else if fullString.characterCount > 5 { @@ -379,7 +359,7 @@ extension TextFieldFilledSwiftExample: UITextFieldDelegate { } } else if textField == city { if let range = fullString.rangeOfCharacter(from: CharacterSet.decimalDigits), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { cityController.setErrorText("Error: City can only contain letters", errorAccessibilityValue: nil) } else { @@ -416,22 +396,22 @@ extension TextFieldFilledSwiftExample { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, diff --git a/components/TextFields/examples/TextFieldLegacyExample.swift b/components/TextFields/examples/TextFieldLegacyExample.swift index 80ecb8000de..a597579fe93 100644 --- a/components/TextFields/examples/TextFieldLegacyExample.swift +++ b/components/TextFields/examples/TextFieldLegacyExample.swift @@ -149,15 +149,11 @@ final class TextFieldLegacySwiftExample: UIViewController { scrollView.addSubview(message) let messageController = MDCTextInputControllerLegacyDefault(textInput: message) - #if swift(>=3.2) - message.text = """ - This is where you could put a multi-line message like an email. - - It can even handle new lines. - """ - #else - message.text = "This is where you could put a multi-line message like an email. It can even handle new lines./n" - #endif + message.text = """ + This is where you could put a multi-line message like an email. + + It can even handle new lines. + """ message.textView?.delegate = self messageController.placeholderText = "Message" allTextFieldControllers.append(messageController) @@ -199,8 +195,7 @@ final class TextFieldLegacySwiftExample: UIViewController { options: [], metrics: nil, views: views) - #if swift(>=3.2) - if #available(iOS 11.0, *) { + if #available(iOS 11.0, *) { constraints += [NSLayoutConstraint(item: name, attribute: .top, relatedBy: .equal, @@ -231,23 +226,6 @@ final class TextFieldLegacySwiftExample: UIViewController { multiplier: 1, constant: -20)] } - #else - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - - #endif let stateZipViews = [ "state": state, "zip": zip ] constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[state(80)]-[zip]|", options: [.alignAllTop], @@ -328,7 +306,7 @@ extension TextFieldLegacySwiftExample: UITextFieldDelegate { if textField == zip { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { zipController.setErrorText("Error: Zip can only contain numbers", errorAccessibilityValue: nil) } else if fullString.characterCount > 5 { @@ -339,7 +317,7 @@ extension TextFieldLegacySwiftExample: UITextFieldDelegate { } } else if textField == city { if let range = fullString.rangeOfCharacter(from: CharacterSet.decimalDigits), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { cityController.setErrorText("Error: City can only contain letters", errorAccessibilityValue: nil) } else { @@ -376,22 +354,22 @@ extension TextFieldLegacySwiftExample { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, diff --git a/components/TextFields/examples/TextFieldManualLayoutLegacyExample.swift b/components/TextFields/examples/TextFieldManualLayoutLegacyExample.swift index e14cbcde4ad..8ad428d1744 100644 --- a/components/TextFields/examples/TextFieldManualLayoutLegacyExample.swift +++ b/components/TextFields/examples/TextFieldManualLayoutLegacyExample.swift @@ -256,7 +256,7 @@ extension TextFieldManualLayoutLegacySwiftExample: UITextFieldDelegate { if textField == zip { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { zipController.setErrorText("Error: Zip can only contain numbers", errorAccessibilityValue: nil) } else if fullString.characterCount > 5 { @@ -267,7 +267,7 @@ extension TextFieldManualLayoutLegacySwiftExample: UITextFieldDelegate { } } else if textField == city { if let range = fullString.rangeOfCharacter(from: CharacterSet.decimalDigits), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { cityController.setErrorText("Error: City can only contain letters", errorAccessibilityValue: nil) } else { @@ -298,22 +298,22 @@ extension TextFieldManualLayoutLegacySwiftExample { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, diff --git a/components/TextFields/examples/TextFieldOutlinedExample.swift b/components/TextFields/examples/TextFieldOutlinedExample.swift index c4b89b9b9d2..0b2716ad5d9 100644 --- a/components/TextFields/examples/TextFieldOutlinedExample.swift +++ b/components/TextFields/examples/TextFieldOutlinedExample.swift @@ -167,15 +167,11 @@ final class TextFieldOutlinedSwiftExample: UIViewController { scrollView.addSubview(message) let messageController = MDCTextInputControllerOutlinedTextArea(textInput: message) message.textView?.delegate = self - #if swift(>=3.2) - message.text = """ - This is where you could put a multi-line message like an email. - - It can even handle new lines. - """ - #else - message.text = "This is where you could put a multi-line message like an email. It can even handle new lines./n" - #endif + message.text = """ + This is where you could put a multi-line message like an email. + + It can even handle new lines. + """ messageController.placeholderText = "Message" allTextFieldControllers.append(messageController) @@ -220,39 +216,22 @@ final class TextFieldOutlinedSwiftExample: UIViewController { metrics: nil, views: views) - #if swift(>=3.2) - if #available(iOS 11.0, *) { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } else { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } - #else + if #available(iOS 11.0, *) { + constraints += [NSLayoutConstraint(item: name, + attribute: .top, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .top, + multiplier: 1, + constant: 20), + NSLayoutConstraint(item: message, + attribute: .bottom, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .bottomMargin, + multiplier: 1, + constant: -20)] + } else { constraints += [NSLayoutConstraint(item: name, attribute: .top, relatedBy: .equal, @@ -267,7 +246,7 @@ final class TextFieldOutlinedSwiftExample: UIViewController { attribute: .bottomMargin, multiplier: 1, constant: -20)] - #endif + } let stateZipViews = [ "state": state, "zip": zip ] constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[state(80)]-[zip]|", @@ -336,14 +315,15 @@ extension TextFieldOutlinedSwiftExample: UITextFieldDelegate { if textField == state { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters.inverted), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { stateController.setErrorText("Error: State can only contain letters", errorAccessibilityValue: nil) } else { stateController.setErrorText(nil, errorAccessibilityValue: nil) } - } else if textField == zip { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), - fullString[range].characterCount > 0 { + } else if textField == zip { + if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), + String(fullString[range]).characterCount > 0 { zipController.setErrorText("Error: Zip can only contain numbers", errorAccessibilityValue: nil) } else if fullString.characterCount > 5 { @@ -354,7 +334,7 @@ extension TextFieldOutlinedSwiftExample: UITextFieldDelegate { } } else if textField == city { if let range = fullString.rangeOfCharacter(from: CharacterSet.decimalDigits), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { cityController.setErrorText("Error: City can only contain letters", errorAccessibilityValue: nil) } else { @@ -391,22 +371,22 @@ extension TextFieldOutlinedSwiftExample { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, diff --git a/components/TextFields/examples/TextFieldSemanticColorThemer.swift b/components/TextFields/examples/TextFieldSemanticColorThemer.swift index b30ed50c4c2..d66c1364bbf 100644 --- a/components/TextFields/examples/TextFieldSemanticColorThemer.swift +++ b/components/TextFields/examples/TextFieldSemanticColorThemer.swift @@ -102,7 +102,6 @@ final class TextFieldSemanticColorThemer: UIViewController { multiplier: 1, constant: 0)] - #if swift(>=3.2) if #available(iOS 11.0, *) { constraints += [NSLayoutConstraint(item: textfieldStandard, attribute: .top, @@ -134,22 +133,6 @@ final class TextFieldSemanticColorThemer: UIViewController { multiplier: 1, constant: -20)] } - #else - constraints += [NSLayoutConstraint(item: textfieldStandard, - attribute: .top, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: textfieldAlternative, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - #endif NSLayoutConstraint.activate(constraints) } @@ -195,22 +178,22 @@ extension TextFieldSemanticColorThemer { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, diff --git a/components/TextFields/examples/TextFieldUnderlineExample.swift b/components/TextFields/examples/TextFieldUnderlineExample.swift index a301384053c..317397ffcba 100644 --- a/components/TextFields/examples/TextFieldUnderlineExample.swift +++ b/components/TextFields/examples/TextFieldUnderlineExample.swift @@ -151,15 +151,8 @@ final class TextFieldUnderlineSwiftExample: UIViewController { scrollView.addSubview(message) let messageController = MDCTextInputControllerUnderline(textInput: message) message.textView?.delegate = self - #if swift(>=3.2) - message.text = """ - This is where you could put a multi-line message like an email. - - It can even handle new lines. - """ - #else - message.text = "This is where you could put a multi-line message like an email. It can even handle new lines./n" - #endif + message.text = "This is where you could put a multi-line message like an email." + "\n\n" + + "It can even handle new lines." message.multilineDelegate = self messageController.placeholderText = "Message" allTextFieldControllers.append(messageController) @@ -202,39 +195,22 @@ final class TextFieldUnderlineSwiftExample: UIViewController { metrics: nil, views: views) - #if swift(>=3.2) - if #available(iOS 11.0, *) { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } else { - constraints += [NSLayoutConstraint(item: name, - attribute: .top, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1, - constant: 20), - NSLayoutConstraint(item: message, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1, - constant: -20)] - } - #else + if #available(iOS 11.0, *) { + constraints += [NSLayoutConstraint(item: name, + attribute: .top, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .top, + multiplier: 1, + constant: 20), + NSLayoutConstraint(item: message, + attribute: .bottom, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .bottomMargin, + multiplier: 1, + constant: -20)] + } else { constraints += [NSLayoutConstraint(item: name, attribute: .top, relatedBy: .equal, @@ -249,7 +225,7 @@ final class TextFieldUnderlineSwiftExample: UIViewController { attribute: .bottomMargin, multiplier: 1, constant: -20)] - #endif + } let stateZipViews = [ "state": state, "zip": zip ] constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[state(80)]-[zip]|", @@ -335,7 +311,7 @@ extension TextFieldUnderlineSwiftExample: UITextFieldDelegate { if textField == state { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters.inverted), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { stateController.setErrorText("Error: State can only contain letters", errorAccessibilityValue: nil) } else { @@ -343,7 +319,7 @@ extension TextFieldUnderlineSwiftExample: UITextFieldDelegate { } } else if textField == zip { if let range = fullString.rangeOfCharacter(from: CharacterSet.letters), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { zipController.setErrorText("Error: Zip can only contain numbers", errorAccessibilityValue: nil) } else if fullString.characterCount > 5 { @@ -354,7 +330,7 @@ extension TextFieldUnderlineSwiftExample: UITextFieldDelegate { } } else if textField == city { if let range = fullString.rangeOfCharacter(from: CharacterSet.decimalDigits), - fullString[range].characterCount > 0 { + String(fullString[range]).characterCount > 0 { cityController.setErrorText("Error: City can only contain letters", errorAccessibilityValue: nil) } else { @@ -397,22 +373,22 @@ extension TextFieldUnderlineSwiftExample { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, @@ -450,10 +426,6 @@ extension TextFieldUnderlineSwiftExample { internal extension String { var characterCount: Int { - #if swift(>=3.2) - return self.count - #else - return self.characters.count - #endif + return self.count } } diff --git a/components/TextFields/examples/experimental/InputTextFieldStoryboardExampleViewController.swift b/components/TextFields/examples/experimental/InputTextFieldStoryboardExampleViewController.swift index 751de6f5097..36efc8d5b2b 100644 --- a/components/TextFields/examples/experimental/InputTextFieldStoryboardExampleViewController.swift +++ b/components/TextFields/examples/experimental/InputTextFieldStoryboardExampleViewController.swift @@ -60,22 +60,22 @@ extension SimpleTextFieldStoryboardExampleViewController { notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let _ = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let _ = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } } diff --git a/components/TextFields/examples/supplemental/TextFieldKitchenSinkExampleSupplemental.swift b/components/TextFields/examples/supplemental/TextFieldKitchenSinkExampleSupplemental.swift index 44766d7f094..0ce6c293154 100644 --- a/components/TextFields/examples/supplemental/TextFieldKitchenSinkExampleSupplemental.swift +++ b/components/TextFields/examples/supplemental/TextFieldKitchenSinkExampleSupplemental.swift @@ -52,7 +52,7 @@ extension TextFieldKitchenSinkSwiftExample { NotificationCenter.default.addObserver(self, selector: #selector(TextFieldKitchenSinkSwiftExample.contentSizeCategoryDidChange(notif:)), - name:.UIContentSizeCategoryDidChange, + name: UIContentSizeCategory.didChangeNotification, object: nil) } @@ -184,7 +184,7 @@ extension TextFieldKitchenSinkSwiftExample { control } - let allTextFields = allTextFieldControllers.flatMap { $0.textInput } + let allTextFields = allTextFieldControllers.compactMap { $0.textInput } let textFieldsString = allTextFields.reduce("", concatenatingClosure) var textFields = [String: UIView]() @@ -192,7 +192,7 @@ extension TextFieldKitchenSinkSwiftExample { textFields[unique(from: textInput, with: prefix)] = textInput } - let allTextViews = allMultilineTextFieldControllers.flatMap { $0.textInput } + let allTextViews = allMultilineTextFieldControllers.compactMap { $0.textInput } let textViewsString = allTextViews.reduce("", concatenatingClosure) var textViews = [String: UIView]() @@ -228,7 +228,7 @@ extension TextFieldKitchenSinkSwiftExample { attribute: .leadingMargin, multiplier: 1.0, constant: 0.0) - leading.priority = 750.0 + leading.priority = UILayoutPriority.defaultHigh leading.isActive = true let trailing = NSLayoutConstraint(item: value, @@ -238,7 +238,7 @@ extension TextFieldKitchenSinkSwiftExample { attribute: .trailing, multiplier: 1.0, constant: 0.0) - trailing.priority = 750.0 + trailing.priority = UILayoutPriority.defaultHigh trailing.isActive = true } } @@ -248,7 +248,7 @@ extension TextFieldKitchenSinkSwiftExample { metrics: nil, views: views)) - controllersFullWidth.flatMap { $0.textInput }.forEach { textInput in + controllersFullWidth.compactMap { $0.textInput }.forEach { textInput in NSLayoutConstraint(item: textInput, attribute: .leading, relatedBy: .equal, @@ -275,54 +275,37 @@ extension TextFieldKitchenSinkSwiftExample { } // These used to be done in the visual format string but iOS 11 changed that. - #if swift(>=3.2) - if #available(iOS 11.0, *) { - NSLayoutConstraint(item: singleLabel, - attribute: .topMargin, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .top, - multiplier: 1.0, - constant: 20).isActive = true - NSLayoutConstraint(item: allControls.last as Any, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView.contentLayoutGuide, - attribute: .bottomMargin, - multiplier: 1.0, - constant: -20).isActive = true - } else { - NSLayoutConstraint(item: singleLabel, - attribute: .topMargin, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1.0, - constant: 20).isActive = true - NSLayoutConstraint(item: allControls.last as Any, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1.0, - constant: -20).isActive = true - } - #else - NSLayoutConstraint(item: singleLabel, - attribute: .topMargin, - relatedBy: .equal, - toItem: scrollView, - attribute: .top, - multiplier: 1.0, - constant: 20).isActive = true - NSLayoutConstraint(item: allControls.last as Any, - attribute: .bottom, - relatedBy: .equal, - toItem: scrollView, - attribute: .bottomMargin, - multiplier: 1.0, - constant: -20).isActive = true - #endif + if #available(iOS 11.0, *) { + NSLayoutConstraint(item: singleLabel, + attribute: .topMargin, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .top, + multiplier: 1.0, + constant: 20).isActive = true + NSLayoutConstraint(item: allControls.last as Any, + attribute: .bottom, + relatedBy: .equal, + toItem: scrollView.contentLayoutGuide, + attribute: .bottomMargin, + multiplier: 1.0, + constant: -20).isActive = true + } else { + NSLayoutConstraint(item: singleLabel, + attribute: .topMargin, + relatedBy: .equal, + toItem: scrollView, + attribute: .top, + multiplier: 1.0, + constant: 20).isActive = true + NSLayoutConstraint(item: allControls.last as Any, + attribute: .bottom, + relatedBy: .equal, + toItem: scrollView, + attribute: .bottomMargin, + multiplier: 1.0, + constant: -20).isActive = true + } registerKeyboardNotifications() addGestureRecognizer() @@ -339,22 +322,22 @@ extension TextFieldKitchenSinkSwiftExample { notificationCenter.addObserver( self, selector: #selector(TextFieldKitchenSinkSwiftExample.keyboardWillShow(notif:)), - name: .UIKeyboardWillShow, + name: UIResponder.keyboardWillShowNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(TextFieldKitchenSinkSwiftExample.keyboardWillShow(notif:)), - name: .UIKeyboardWillChangeFrame, + name: UIResponder.keyboardWillChangeFrameNotification, object: nil) notificationCenter.addObserver( self, selector: #selector(TextFieldKitchenSinkSwiftExample.keyboardWillHide(notif:)), - name: .UIKeyboardWillHide, + name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(notif: Notification) { - guard let frame = notif.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect else { + guard let frame = notif.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return } scrollView.contentInset = UIEdgeInsets(top: 0.0, @@ -389,7 +372,7 @@ extension TextFieldKitchenSinkSwiftExample { partialTitle = "Underline View Mode" } - let closure: (UITextFieldViewMode, String) -> Void = { mode, title in + let closure: (UITextField.ViewMode, String) -> Void = { mode, title in controllersToChange.forEach { controller in if button == self.characterModeButton { controller.characterCountViewMode = mode @@ -413,10 +396,10 @@ extension TextFieldKitchenSinkSwiftExample { func presentAlert (alert: UIAlertController, partialTitle: String, - closure: @escaping (_ mode: UITextFieldViewMode, _ title: String) -> Void) -> Void { + closure: @escaping (_ mode: UITextField.ViewMode, _ title: String) -> Void) -> Void { for rawMode in 0...3 { - let mode = UITextFieldViewMode(rawValue: rawMode)! + let mode = UITextField.ViewMode(rawValue: rawMode)! alert.addAction(UIAlertAction(title: modeName(mode: mode), style: .default, handler: { _ in @@ -427,7 +410,7 @@ extension TextFieldKitchenSinkSwiftExample { present(alert, animated: true, completion: nil) } - func modeName(mode: UITextFieldViewMode) -> String { + func modeName(mode: UITextField.ViewMode) -> String { switch mode { case .always: return "Always" diff --git a/components/TextFields/tests/unit/TextFieldControllerLegacyTests.swift b/components/TextFields/tests/unit/TextFieldControllerLegacyTests.swift index 420615e4126..fb2ffd436c7 100644 --- a/components/TextFields/tests/unit/TextFieldControllerLegacyTests.swift +++ b/components/TextFields/tests/unit/TextFieldControllerLegacyTests.swift @@ -253,7 +253,7 @@ class TextFieldControllerDefaultLegacyTests: XCTestCase { textField.setNeedsLayout() textField.layoutIfNeeded() - let estimatedTextFrame = UIEdgeInsetsInsetRect(textField.bounds, controller.textInsets(UIEdgeInsets())) + let estimatedTextFrame = textField.bounds.inset(by: controller.textInsets(UIEdgeInsets())) XCTAssertFalse(textField.placeholderLabel.frame.intersects(estimatedTextFrame)) } diff --git a/components/TextFields/tests/unit/TextFieldTests.swift b/components/TextFields/tests/unit/TextFieldTests.swift index 8d886df44dc..124fbab05bc 100644 --- a/components/TextFields/tests/unit/TextFieldTests.swift +++ b/components/TextFields/tests/unit/TextFieldTests.swift @@ -33,7 +33,9 @@ class TextFieldTests: XCTestCase { let textField = MDCTextField() for constraint in textField.constraints { - XCTAssertLessThanOrEqual(constraint.priority, UILayoutPriorityDefaultLow + 10, String(describing: constraint)) + XCTAssertLessThanOrEqual(constraint.priority.rawValue, + UILayoutPriority.defaultLow.rawValue + 10, + String(describing: constraint)) } } @@ -47,7 +49,8 @@ class TextFieldTests: XCTestCase { textField.textInsetsMode = .never textField.borderView?.borderFillColor = .purple - textField.borderView?.borderPath = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 100, height: 100)) + textField.borderView?.borderPath = + UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 100, height: 100)) textField.borderView?.borderStrokeColor = .yellow textField.clearButton.tintColor = .red textField.clearButtonMode = .always @@ -67,9 +70,12 @@ class TextFieldTests: XCTestCase { XCTAssertEqual(textField.textInsetsMode, textFieldCopy.textInsetsMode) XCTAssertEqual(textField.attributedPlaceholder, textFieldCopy.attributedPlaceholder) XCTAssertEqual(textField.attributedText, textFieldCopy.attributedText) - XCTAssertEqual(textField.borderView?.borderFillColor, textFieldCopy.borderView?.borderFillColor) - XCTAssertEqual(textField.borderView?.borderPath?.bounds.integral, textFieldCopy.borderView?.borderPath?.bounds.integral) - XCTAssertEqual(textField.borderView?.borderStrokeColor, textFieldCopy.borderView?.borderStrokeColor) + XCTAssertEqual(textField.borderView?.borderFillColor, + textFieldCopy.borderView?.borderFillColor) + XCTAssertEqual(textField.borderView?.borderPath?.bounds.integral, + textFieldCopy.borderView?.borderPath?.bounds.integral) + XCTAssertEqual(textField.borderView?.borderStrokeColor, + textFieldCopy.borderView?.borderStrokeColor) XCTAssertEqual(textField.clearButton.tintColor, textFieldCopy.clearButton.tintColor) XCTAssertEqual(textField.clearButtonMode, textFieldCopy.clearButtonMode) XCTAssertEqual(textField.cursorColor, textFieldCopy.cursorColor) diff --git a/components/Typography/examples/TypographyFontListExample.swift b/components/Typography/examples/TypographyFontListExample.swift index 7b8526121c7..86322cdbaf2 100644 --- a/components/Typography/examples/TypographyFontListExample.swift +++ b/components/Typography/examples/TypographyFontListExample.swift @@ -24,7 +24,7 @@ class TypographyFontListExampleViewController: UITableViewController { self.tableView.separatorStyle = .none - self.tableView.rowHeight = UITableViewAutomaticDimension + self.tableView.rowHeight = UITableView.automaticDimension self.tableView.estimatedRowHeight = 50 } @@ -64,7 +64,7 @@ class TypographyFontListExampleViewController: UITableViewController { self.init(style: .plain) } - override init(style: UITableViewStyle) { + override init(style: UITableView.Style) { super.init(style: style) self.title = "Font list" diff --git a/components/private/Dragons/examples/ZShadow.swift b/components/private/Dragons/examples/ZShadow.swift index b938cc5007f..82c2de18e8c 100644 --- a/components/private/Dragons/examples/ZShadow.swift +++ b/components/private/Dragons/examples/ZShadow.swift @@ -84,7 +84,7 @@ class ZShadowViewController: UIViewController { } - func squaresTapped() { + @objc func squaresTapped() { greenBannerLeadingConstraintCollapsed.isActive = !greenBannerLeadingConstraintCollapsed.isActive blueBannerLeadingConstraintCollapsed.isActive = !blueBannerLeadingConstraintCollapsed.isActive diff --git a/components/private/Snapshot/BUILD b/components/private/Snapshot/BUILD index c3dc7ea0fcd..dabeba80dce 100644 --- a/components/private/Snapshot/BUILD +++ b/components/private/Snapshot/BUILD @@ -34,7 +34,7 @@ swift_library( srcs = glob(["src/*.swift"]), copts = [ "-swift-version", - "3", + "4.2", ], ) diff --git a/material_components_ios.bzl b/material_components_ios.bzl index 9a0092ade6a..2fc5416ecd6 100644 --- a/material_components_ios.bzl +++ b/material_components_ios.bzl @@ -158,7 +158,7 @@ def mdc_examples_swift_library( visibility = visibility, copts = [ "-swift-version", - "3", + "4.2", ], srcs = native.glob([ "examples/*.swift",