Skip to content

Commit

Permalink
Swiftlint rules update
Browse files Browse the repository at this point in the history
Fix some warnings
  • Loading branch information
dogo committed Jan 6, 2019
1 parent 4eacdb6 commit bd957c1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 43 deletions.
55 changes: 50 additions & 5 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -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

- 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
49 changes: 32 additions & 17 deletions AKSideMenu/AKSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -224,7 +234,8 @@ import UIKit
self.showRightMenuViewController()
}

@objc public func hideMenuViewController() {
@objc
public func hideMenuViewController() {
self.hideMenuViewControllerAnimated(true)
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -434,7 +448,7 @@ import UIKit
UIApplication.shared.beginIgnoringInteractionEvents()
UIView.animate(withDuration: self.animationDuration, animations: {
animationBlock()
}, completion: { (_) in
}, completion: { _ in
UIApplication.shared.endIgnoringInteractionEvents()
completionBlock()
})
Expand Down Expand Up @@ -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)

Expand Down
20 changes: 9 additions & 11 deletions AKSideMenu/UIViewController+AKSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions AKSideMenuExamples/Simple/AKSideMenuSimple/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AKSideMenuDelegate {
// MARK: - <AKSideMenuDelegate>

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(_:)))

Expand All @@ -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
Expand All @@ -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")
}
}

0 comments on commit bd957c1

Please sign in to comment.