From 61b58bc380d07bf55154168d90b9c4efc8378b59 Mon Sep 17 00:00:00 2001 From: Alexandre Podlewski Date: Mon, 4 Mar 2024 15:40:26 +0100 Subject: [PATCH] Fix Swiftlint warnings --- .../NavigationBarExtension/AppDelegate.swift | 27 +++---- .../Step2ViewController.swift | 6 +- .../SwitchExtensionTableViewController.swift | 1 + .../ViewController.swift | 11 --- Example/Tests/Tests.swift | 18 ----- ...bleNavigationBarNavigationController.swift | 74 +++++++++---------- .../Classes/UIToolbar+Appearance.swift | 24 +++--- 7 files changed, 59 insertions(+), 102 deletions(-) diff --git a/Example/NavigationBarExtension/AppDelegate.swift b/Example/NavigationBarExtension/AppDelegate.swift index c890bad..3502a81 100644 --- a/Example/NavigationBarExtension/AppDelegate.swift +++ b/Example/NavigationBarExtension/AppDelegate.swift @@ -17,6 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // swiftlint:disable:previous discouraged_optional_collection setUpAppearance() let window = UIWindow(frame: UIScreen.main.bounds) self.window = window @@ -38,20 +39,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { UINavigationBar .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) .tintColor = UIColor.purple - if #available(iOS 13, *) { - let appearance = UINavigationBarAppearance() - appearance.configureWithDefaultBackground() - UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .standardAppearance = appearance - UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .compactAppearance = appearance - UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .scrollEdgeAppearance = appearance - } else { - ExtensibleNavigationBarNavigationController.ad_isTranslucent = false - } + let appearance = UINavigationBarAppearance() + appearance.configureWithDefaultBackground() + UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .standardAppearance = appearance + UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .compactAppearance = appearance + UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .scrollEdgeAppearance = appearance } } diff --git a/Example/NavigationBarExtension/Step2ViewController.swift b/Example/NavigationBarExtension/Step2ViewController.swift index f23ab35..5ac3b7e 100644 --- a/Example/NavigationBarExtension/Step2ViewController.swift +++ b/Example/NavigationBarExtension/Step2ViewController.swift @@ -44,11 +44,7 @@ class Step2ViewController: UIViewController, UITableViewDataSource, UITableViewD } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - if section.isMultiple(of: 2) { - return "Country" - } else { - return "Region" - } + return section.isMultiple(of: 2) ? "Country" : "Region" } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { diff --git a/Example/NavigationBarExtension/SwitchExtensionTableViewController.swift b/Example/NavigationBarExtension/SwitchExtensionTableViewController.swift index 7e16f0c..60fc94b 100644 --- a/Example/NavigationBarExtension/SwitchExtensionTableViewController.swift +++ b/Example/NavigationBarExtension/SwitchExtensionTableViewController.swift @@ -19,6 +19,7 @@ class SwitchExtensionTableViewController: UIViewController { super.init(nibName: nil, bundle: nil) } + @available(*, unavailable) required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/Example/NavigationBarExtension/ViewController.swift b/Example/NavigationBarExtension/ViewController.swift index ad80583..cc295ff 100644 --- a/Example/NavigationBarExtension/ViewController.swift +++ b/Example/NavigationBarExtension/ViewController.swift @@ -9,15 +9,4 @@ import UIKit class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - } diff --git a/Example/Tests/Tests.swift b/Example/Tests/Tests.swift index 5d9750d..2d72580 100644 --- a/Example/Tests/Tests.swift +++ b/Example/Tests/Tests.swift @@ -2,26 +2,8 @@ import XCTest import ADNavigationBarExtension class Tests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - func testExample() { // This is an example of a functional test case. XCTAssert(true, "Pass") } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } } diff --git a/NavigationBarExtension/Classes/ExtensibleNavigationBarNavigationController.swift b/NavigationBarExtension/Classes/ExtensibleNavigationBarNavigationController.swift index fe8d1fe..09c6a60 100644 --- a/NavigationBarExtension/Classes/ExtensibleNavigationBarNavigationController.swift +++ b/NavigationBarExtension/Classes/ExtensibleNavigationBarNavigationController.swift @@ -10,8 +10,7 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController // ?!!! (Samuel Gallet) 29/01/2020 isTranslucent property does not work with iOS 12. Use this property // to set isTranslucent to the custom navigationBar with iOS 12 @available(iOS, deprecated: 13.0, message: "Use appearance instead of this property") - // swiftlint:disable:next identifier_name - public static var ad_isTranslucent: Bool = true + public static var ad_isTranslucent = true public private(set) var navigationBarToolbar: UIToolbar? public private(set) var navigationBarExtensionToolbar: UIToolbar? @@ -60,6 +59,7 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController // MARK: - NSObject + // swiftlint:disable:next implicitly_unwrapped_optional override public func responds(to aSelector: Selector!) -> Bool { if shouldForwardSelector(aSelector) { return navigationControllerDelegate?.responds(to: aSelector) ?? false @@ -67,6 +67,7 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController return super.responds(to: aSelector) } + // swiftlint:disable:next implicitly_unwrapped_optional override public func forwardingTarget(for aSelector: Selector!) -> Any? { if shouldForwardSelector(aSelector) { return navigationControllerDelegate @@ -78,7 +79,7 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController public func setNavigationBarExtensionView(_ view: UIView?, forHeight height: CGFloat = 0) { navBarExtensionView?.removeFromSuperview() - guard let view = view else { + guard let view else { self.navBarExtensionView = nil navigationBarAdditionalSize = height updateShadowImage() @@ -183,6 +184,7 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController return view } + // swiftlint:disable:next implicitly_unwrapped_optional private func shouldForwardSelector(_ aSelector: Selector!) -> Bool { let description = protocol_getMethodDescription(UINavigationControllerDelegate.self, aSelector, false, true) return @@ -197,42 +199,38 @@ public class ExtensibleNavigationBarNavigationController: UINavigationController private func updateShadowImage() { let needsToShowExtension = self.needsToShowExtension(for: topViewController) - if #available(iOS 13, *) { - let compactNavigationBarAppearance = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .compactAppearance - let scrollEdgeNavigationBarAppearance = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .scrollEdgeAppearance - let standardNavigationBarAppearance: UINavigationBarAppearance? = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .standardAppearance - var color = needsToShowExtension - ? nil - : standardNavigationBarAppearance?.shadowColor - if let standardNavigationBarAppearance = standardNavigationBarAppearance { - navigationBar.standardAppearance = UINavigationBarAppearance( - barAppearance: standardNavigationBarAppearance - ) - navigationBar.standardAppearance.shadowColor = color - } - color = needsToShowExtension - ? nil - : scrollEdgeNavigationBarAppearance?.shadowColor - navigationBar.scrollEdgeAppearance = scrollEdgeNavigationBarAppearance.map { - UINavigationBarAppearance(barAppearance: $0) - } - navigationBar.scrollEdgeAppearance?.shadowColor = color - color = needsToShowExtension - ? nil - : compactNavigationBarAppearance?.shadowColor - navigationBar.compactAppearance = compactNavigationBarAppearance.map { - UINavigationBarAppearance(barAppearance: $0) - } - navigationBar.compactAppearance?.shadowColor = color - } else { - navigationBar.shadowImage = needsToShowExtension ? UIImage() : nil + let compactNavigationBarAppearance = UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .compactAppearance + let scrollEdgeNavigationBarAppearance = UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .scrollEdgeAppearance + let standardNavigationBarAppearance: UINavigationBarAppearance? = UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .standardAppearance + var color = needsToShowExtension + ? nil + : standardNavigationBarAppearance?.shadowColor + if let standardNavigationBarAppearance { + navigationBar.standardAppearance = UINavigationBarAppearance( + barAppearance: standardNavigationBarAppearance + ) + navigationBar.standardAppearance.shadowColor = color + } + color = needsToShowExtension + ? nil + : scrollEdgeNavigationBarAppearance?.shadowColor + navigationBar.scrollEdgeAppearance = scrollEdgeNavigationBarAppearance.map { + UINavigationBarAppearance(barAppearance: $0) + } + navigationBar.scrollEdgeAppearance?.shadowColor = color + color = needsToShowExtension + ? nil + : compactNavigationBarAppearance?.shadowColor + navigationBar.compactAppearance = compactNavigationBarAppearance.map { + UINavigationBarAppearance(barAppearance: $0) } + navigationBar.compactAppearance?.shadowColor = color } private func resetExtensionContainerBottomConstraint() { diff --git a/NavigationBarExtension/Classes/UIToolbar+Appearance.swift b/NavigationBarExtension/Classes/UIToolbar+Appearance.swift index 7e7719d..8ef10f4 100644 --- a/NavigationBarExtension/Classes/UIToolbar+Appearance.swift +++ b/NavigationBarExtension/Classes/UIToolbar+Appearance.swift @@ -17,21 +17,15 @@ extension UIToolbar { .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) .barTintColor isTranslucent = ExtensibleNavigationBarNavigationController.ad_isTranslucent - if #available(iOS 13, *) { - let compactNavigationBarAppearance = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .compactAppearance - compactAppearance = compactNavigationBarAppearance.map { UIToolbarAppearance(barAppearance: $0) } - let standardNavigationBarAppearance: UINavigationBarAppearance? = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .standardAppearance - if let appearance = standardNavigationBarAppearance { - standardAppearance = UIToolbarAppearance(barAppearance: appearance) - } - } else { - backgroundColor = UINavigationBar - .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) - .backgroundColor + let compactNavigationBarAppearance = UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .compactAppearance + compactAppearance = compactNavigationBarAppearance.map { UIToolbarAppearance(barAppearance: $0) } + let standardNavigationBarAppearance: UINavigationBarAppearance? = UINavigationBar + .appearance(whenContainedInInstancesOf: [ExtensibleNavigationBarNavigationController.self]) + .standardAppearance + if let appearance = standardNavigationBarAppearance { + standardAppearance = UIToolbarAppearance(barAppearance: appearance) } } }