Skip to content

Commit

Permalink
Fix Swiftlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-pod committed Mar 4, 2024
1 parent 82b2b00 commit 61b58bc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 102 deletions.
27 changes: 12 additions & 15 deletions Example/NavigationBarExtension/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
6 changes: 1 addition & 5 deletions Example/NavigationBarExtension/Step2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
11 changes: 0 additions & 11 deletions Example/NavigationBarExtension/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

}
18 changes: 0 additions & 18 deletions Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -60,13 +59,15 @@ 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
}
return super.responds(to: aSelector)
}

// swiftlint:disable:next implicitly_unwrapped_optional
override public func forwardingTarget(for aSelector: Selector!) -> Any? {
if shouldForwardSelector(aSelector) {
return navigationControllerDelegate
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
24 changes: 9 additions & 15 deletions NavigationBarExtension/Classes/UIToolbar+Appearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 61b58bc

Please sign in to comment.