diff --git a/.swiftlint.yml b/.swiftlint.yml index 5b20ed0..7c9e51e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,51 @@ -disabled_rules: # rule identifiers to exclude from running - - line_length +opt_in_rules: + - array_init + - attributes + - closure_end_indentation + - closure_spacing + - discouraged_object_literal + - discouraged_optional_boolean + - empty_count + - empty_string + - explicit_init + - fatal_error_message - file_length - - function_body_length - - type_body_length - \ No newline at end of file + - first_where + - force_cast + - force_try + - force_unwrapping + - implicit_return + - implicitly_unwrapped_optional + - joined_default_parameter + - multiline_parameters + - operator_usage_whitespace + - overridden_super_call + - override_in_extension + - prefixed_toplevel_constant + - private_action + - private_outlet + - prohibited_super_call + - redundant_nil_coalescing + - sorted_first_last + - switch_case_on_newline + - trailing_closure + - unneeded_parentheses_in_closure_argument + - vertical_parameter_alignment_on_call + - yoda_condition + +line_length: 160 + +function_body_length: 80 + +line_length: 180 + +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Pods + - Carthage + +custom_rules: + quickspec_class_name: + name: "Invalid Test Class Name" + regex: "class\\s+(.*)[^Tests]:\\s+QuickSpec" + message: "A test class name must end with 'Tests'" + severity: error diff --git a/AKSideMenu/AKSideMenu.swift b/AKSideMenu/AKSideMenu.swift index 7091f1d..dda26a9 100644 --- a/AKSideMenu/AKSideMenu.swift +++ b/AKSideMenu/AKSideMenu.swift @@ -8,18 +8,28 @@ import UIKit -@objc public protocol AKSideMenuDelegate { - @objc optional func sideMenu(_ sideMenu: AKSideMenu, shouldRecognizeGesture recognizer: UIGestureRecognizer, simultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool - @objc optional func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool - @objc optional func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool - @objc optional func sideMenu(_ sideMenu: AKSideMenu, didRecognizePanGesture recognizer: UIPanGestureRecognizer) - @objc optional func sideMenu(_ sideMenu: AKSideMenu, willShowMenuViewController menuViewController: UIViewController) - @objc optional func sideMenu(_ sideMenu: AKSideMenu, didShowMenuViewController menuViewController: UIViewController) - @objc optional func sideMenu(_ sideMenu: AKSideMenu, willHideMenuViewController menuViewController: UIViewController) - @objc optional func sideMenu(_ sideMenu: AKSideMenu, didHideMenuViewController menuViewController: UIViewController) +@objc +public protocol AKSideMenuDelegate { + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, shouldRecognizeGesture recognizer: UIGestureRecognizer, simultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, didRecognizePanGesture recognizer: UIPanGestureRecognizer) + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, willShowMenuViewController menuViewController: UIViewController) + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, didShowMenuViewController menuViewController: UIViewController) + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, willHideMenuViewController menuViewController: UIViewController) + @objc + optional func sideMenu(_ sideMenu: AKSideMenu, didHideMenuViewController menuViewController: UIViewController) } -@IBDesignable open class AKSideMenu: UIViewController, UIGestureRecognizerDelegate { +@IBDesignable +open class AKSideMenu: UIViewController, UIGestureRecognizerDelegate { var visible: Bool = false var leftMenuVisible: Bool = false @@ -62,7 +72,7 @@ import UIKit @IBInspectable public var menuPrefersStatusBarHidden: Bool = false public weak var delegate: AKSideMenuDelegate? - public var animationDuration: TimeInterval = 0.35 + public var animationDuration: TimeInterval = 0.35 public var menuViewControllerTransformation: CGAffineTransform? public var panGestureEnabled: Bool = true public var panFromEdge: Bool = true @@ -204,7 +214,7 @@ import UIKit self.contentViewShadowRadius = 8.0 self.contentViewFadeOutAlpha = 1.0 self.contentViewInLandscapeOffsetCenterX = 30.0 - self.contentViewInPortraitOffsetCenterX = 30.0 + self.contentViewInPortraitOffsetCenterX = 30.0 self.contentViewScaleValue = 0.7 } @@ -224,7 +234,8 @@ import UIKit self.showRightMenuViewController() } - @objc public func hideMenuViewController() { + @objc + public func hideMenuViewController() { self.hideMenuViewControllerAnimated(true) } @@ -243,7 +254,7 @@ import UIKit UIView.animate(withDuration: self.animationDuration, animations: { contentViewController.view.alpha = 1 - }, completion: { (_) in + }, completion: { _ in if let contentViewController = self.contentViewController { self.hideViewController(contentViewController) } @@ -307,7 +318,10 @@ import UIKit self.contentViewContainer.transform = .identity } - self.contentViewContainer.center = CGPoint(x: (UIApplication.shared.statusBarOrientation.isLandscape ? self.contentViewInLandscapeOffsetCenterX + self.view.frame.width : self.contentViewInPortraitOffsetCenterX + self.view.frame.width), y: self.contentViewContainer.center.y) + let centerX = UIApplication.shared.statusBarOrientation.isLandscape ? + self.contentViewInLandscapeOffsetCenterX : self.contentViewInPortraitOffsetCenterX + self.contentViewContainer.center = CGPoint(x: centerX + self.view.frame.width, + y: self.contentViewContainer.center.y) if self.fadeMenuView { self.menuViewContainer.alpha = 1.0 @@ -434,7 +448,7 @@ import UIKit UIApplication.shared.beginIgnoringInteractionEvents() UIView.animate(withDuration: self.animationDuration, animations: { animationBlock() - }, completion: { (_) in + }, completion: { _ in UIApplication.shared.endIgnoringInteractionEvents() completionBlock() }) @@ -584,7 +598,8 @@ import UIKit // MARK: - Pan gesture recognizer (Private) - @objc func panGestureRecognized(_ recognizer: UIPanGestureRecognizer) { + @objc + func panGestureRecognized(_ recognizer: UIPanGestureRecognizer) { self.delegate?.sideMenu?(self, didRecognizePanGesture: recognizer) diff --git a/AKSideMenu/UIViewController+AKSideMenu.swift b/AKSideMenu/UIViewController+AKSideMenu.swift index ff5d12d..c5fe4b3 100644 --- a/AKSideMenu/UIViewController+AKSideMenu.swift +++ b/AKSideMenu/UIViewController+AKSideMenu.swift @@ -13,19 +13,17 @@ import UIKit extension UIViewController { public var sideMenuViewController: AKSideMenu? { - get { - guard var iterator = self.parent else { return nil } - guard let strClass = String(describing: type(of: iterator)).components(separatedBy: ".").last else { return nil } - - while strClass != nibName { - if iterator is AKSideMenu { - return iterator as? AKSideMenu - } else if iterator.parent != nil && iterator.parent != iterator { - iterator = iterator.parent! - } + guard var iterator = self.parent else { return nil } + guard let strClass = String(describing: type(of: iterator)).components(separatedBy: ".").last else { return nil } + + while strClass != nibName { + if iterator is AKSideMenu { + return iterator as? AKSideMenu + } else if iterator.parent != nil && iterator.parent != iterator { + iterator = iterator.parent! } - return nil } + return nil } // MARK: - Public diff --git a/AKSideMenuExamples/Simple/AKSideMenuSimple/AppDelegate.swift b/AKSideMenuExamples/Simple/AKSideMenuSimple/AppDelegate.swift index 39ebc85..eab57f2 100644 --- a/AKSideMenuExamples/Simple/AKSideMenuSimple/AppDelegate.swift +++ b/AKSideMenuExamples/Simple/AKSideMenuSimple/AppDelegate.swift @@ -43,18 +43,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AKSideMenuDelegate { // MARK: - open func sideMenu(_ sideMenu: AKSideMenu, willShowMenuViewController menuViewController: UIViewController) { - print("willShowMenuViewController") + print("willShowMenuViewController", menuViewController) } open func sideMenu(_ sideMenu: AKSideMenu, didShowMenuViewController menuViewController: UIViewController) { - print("didShowMenuViewController") + print("didShowMenuViewController", menuViewController) } open func sideMenu(_ sideMenu: AKSideMenu, willHideMenuViewController menuViewController: UIViewController) { - print("willHideMenuViewController") + print("willHideMenuViewController ", menuViewController) } open func sideMenu(_ sideMenu: AKSideMenu, didHideMenuViewController menuViewController: UIViewController) { - print("didHideMenuViewController") + print("didHideMenuViewController", menuViewController) } } diff --git a/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/FirstViewController.swift b/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/FirstViewController.swift index e0221ab..2658691 100644 --- a/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/FirstViewController.swift +++ b/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/FirstViewController.swift @@ -25,11 +25,11 @@ open class FirstViewController: UIViewController { open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - NSLog("FirstViewController will appear") + print("FirstViewController will appear") } open override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - NSLog("FirstViewController will disappear") + print("FirstViewController will disappear") } } diff --git a/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/SecondViewController.swift b/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/SecondViewController.swift index 825e88c..344b7e4 100644 --- a/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/SecondViewController.swift +++ b/AKSideMenuExamples/Simple/AKSideMenuSimple/Controllers/SecondViewController.swift @@ -13,7 +13,7 @@ open class SecondViewController: UIViewController { override open func viewDidLoad() { super.viewDidLoad() self.title = "Second Controller" - self.view.backgroundColor = UIColor(red: 255/255.0, green: 202/255.0, blue: 101/255.0, alpha: 1.0) + self.view.backgroundColor = UIColor(red: 255 / 255.0, green: 202 / 255.0, blue: 101 / 255.0, alpha: 1.0) self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Left", style: .plain, target: self, action: #selector(self.presentLeftMenuViewController(_:))) self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right", style: .plain, target: self, action: #selector(self.presentRightMenuViewController(_:))) @@ -25,7 +25,8 @@ open class SecondViewController: UIViewController { self.view.addSubview(button) } - @objc func pushViewController(_ sender: AnyObject) { + @objc + func pushViewController(_ sender: AnyObject) { let viewController = UIViewController() viewController.title = "Pushed Controller" viewController.view.backgroundColor = .white @@ -34,11 +35,11 @@ open class SecondViewController: UIViewController { open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - NSLog("SecondViewController will appear") + print("SecondViewController will appear") } open override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - NSLog("SecondViewController will disappear") + print("SecondViewController will disappear") } }