Fixed some swiftlint warnings

This commit is contained in:
Lucas Farah 2017-01-24 10:24:35 -02:00 committed by Arunav Sanyal
parent 5b6250722f
commit 1885a24296
18 changed files with 173 additions and 194 deletions

View File

@ -43,7 +43,7 @@ extension Array {
} }
/// EZSE: Iterates on each element of the array with its index. (Index, Element) /// EZSE: Iterates on each element of the array with its index. (Index, Element)
public func forEachEnumerated(_ body: @escaping (_ offset: Int, _ element: Element) -> ()) { public func forEachEnumerated(_ body: @escaping (_ offset: Int, _ element: Element) -> Void) {
self.enumerated().forEach(body) self.enumerated().forEach(body)
} }
@ -247,7 +247,7 @@ extension Array {
/// EZSE: Iterates on each element of the array with its index. (Index, Element) /// EZSE: Iterates on each element of the array with its index. (Index, Element)
@available(*, deprecated: 1.7, renamed: "forEachEnumerated(_:)") @available(*, deprecated: 1.7, renamed: "forEachEnumerated(_:)")
public func forEach(_ call: @escaping (Int, Element) -> ()) { public func forEach(_ call: @escaping (Int, Element) -> Void) {
forEachEnumerated(call) forEachEnumerated(call)
} }
@ -293,7 +293,7 @@ extension Array {
/// EZSE: Iterates on each element of the array. /// EZSE: Iterates on each element of the array.
@available(*, deprecated: 1.6, renamed: "forEach(_:)") @available(*, deprecated: 1.6, renamed: "forEach(_:)")
public func each(_ call: (Element) -> ()) { public func each(_ call: (Element) -> Void) {
forEach(call) forEach(call)
} }
@ -306,7 +306,7 @@ extension Array {
/// EZSE: Iterates on each element of the array with its index. (Index, Element) /// EZSE: Iterates on each element of the array with its index. (Index, Element)
@available(*, deprecated: 1.6, renamed: "forEachEnumerated(_:)") @available(*, deprecated: 1.6, renamed: "forEachEnumerated(_:)")
public func each(_ call: @escaping (Int, Element) -> ()) { public func each(_ call: @escaping (Int, Element) -> Void) {
forEachEnumerated(call) forEachEnumerated(call)
} }

View File

@ -12,9 +12,9 @@ import UIKit
///Make sure you use `[weak self] (NSURLRequest) in` if you are using the keyword `self` inside the closure or there might be a memory leak ///Make sure you use `[weak self] (NSURLRequest) in` if you are using the keyword `self` inside the closure or there might be a memory leak
open class BlockWebView: UIWebView, UIWebViewDelegate { open class BlockWebView: UIWebView, UIWebViewDelegate {
open var didStartLoad: ((URLRequest) -> ())? open var didStartLoad: ((URLRequest) -> Void)?
open var didFinishLoad: ((URLRequest) -> ())? open var didFinishLoad: ((URLRequest) -> Void)?
open var didFailLoad: ((URLRequest, Error) -> ())? open var didFailLoad: ((URLRequest, Error) -> Void)?
open var shouldStartLoadingRequest: ((URLRequest) -> (Bool))? open var shouldStartLoadingRequest: ((URLRequest) -> (Bool))?

View File

@ -73,10 +73,10 @@ extension CGFloat {
let twoPi = CGFloat(.pi * 2.0) let twoPi = CGFloat(.pi * 2.0)
var angle = (second - first).truncatingRemainder(dividingBy: twoPi) var angle = (second - first).truncatingRemainder(dividingBy: twoPi)
if angle >= .pi { if angle >= .pi {
angle = angle - twoPi angle -= twoPi
} }
if angle <= -.pi { if angle <= -.pi {
angle = angle + twoPi angle += twoPi
} }
return angle return angle
} }

View File

@ -18,19 +18,15 @@ extension Character {
/// EZSE: Convert the character to lowercase /// EZSE: Convert the character to lowercase
public var lowercased: Character { public var lowercased: Character {
get {
let s = String(self).lowercased() let s = String(self).lowercased()
return s[s.startIndex] return s[s.startIndex]
} }
}
/// EZSE: Convert the character to uppercase /// EZSE: Convert the character to uppercase
public var uppercased: Character { public var uppercased: Character {
get {
let s = String(self).uppercased() let s = String(self).uppercased()
return s[s.startIndex] return s[s.startIndex]
} }
}
/// EZSE : Checks if character is emoji /// EZSE : Checks if character is emoji
var isEmoji: Bool { var isEmoji: Bool {

View File

@ -162,7 +162,7 @@ extension Dictionary where Value: Equatable {
} }
/// EZSE: Combines the first dictionary with the second and returns single dictionary /// EZSE: Combines the first dictionary with the second and returns single dictionary
public func += <KeyType, ValueType> (left: inout Dictionary<KeyType, ValueType>, right: Dictionary<KeyType, ValueType>) { public func += <KeyType, ValueType> (left: inout [KeyType: ValueType], right: [KeyType: ValueType]) {
for (k, v) in right { for (k, v) in right {
left.updateValue(v, forKey: k) left.updateValue(v, forKey: k)
} }

View File

@ -46,7 +46,7 @@ extension Double {
/// EZSE: Absolute value of Double. /// EZSE: Absolute value of Double.
public var abs: Double { public var abs: Double {
if (self > 0) { if self > 0 {
return self return self
} else { } else {
return -self return -self

View File

@ -181,7 +181,7 @@ public struct ez {
} }
/// EZSE: Calls action when a screen shot is taken /// EZSE: Calls action when a screen shot is taken
public static func detectScreenShot(_ action: @escaping () -> ()) { public static func detectScreenShot(_ action: @escaping () -> Void) {
let mainQueue = OperationQueue.main let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationUserDidTakeScreenshot, object: nil, queue: mainQueue) { notification in NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationUserDidTakeScreenshot, object: nil, queue: mainQueue) { notification in
// executes after screenshot // executes after screenshot
@ -205,30 +205,30 @@ public struct ez {
// MARK: - Dispatch // MARK: - Dispatch
/// EZSE: Runs the function after x seconds /// EZSE: Runs the function after x seconds
public static func dispatchDelay(_ second: Double, closure:@escaping ()->()) { public static func dispatchDelay(_ second: Double, closure:@escaping () -> Void) {
DispatchQueue.main.asyncAfter( DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(second * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure) deadline: DispatchTime.now() + Double(Int64(second * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
} }
/// EZSE: Runs function after x seconds /// EZSE: Runs function after x seconds
public static func runThisAfterDelay(seconds: Double, after: @escaping () -> ()) { public static func runThisAfterDelay(seconds: Double, after: @escaping () -> Void) {
runThisAfterDelay(seconds: seconds, queue: DispatchQueue.main, after: after) runThisAfterDelay(seconds: seconds, queue: DispatchQueue.main, after: after)
} }
//TODO: Make this easier //TODO: Make this easier
/// EZSE: Runs function after x seconds with dispatch_queue, use this syntax: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0) /// EZSE: Runs function after x seconds with dispatch_queue, use this syntax: dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)
public static func runThisAfterDelay(seconds: Double, queue: DispatchQueue, after: @escaping ()->()) { public static func runThisAfterDelay(seconds: Double, queue: DispatchQueue, after: @escaping () -> Void) {
let time = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) let time = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
queue.asyncAfter(deadline: time, execute: after) queue.asyncAfter(deadline: time, execute: after)
} }
/// EZSE: Submits a block for asynchronous execution on the main queue /// EZSE: Submits a block for asynchronous execution on the main queue
public static func runThisInMainThread(_ block: @escaping ()->()) { public static func runThisInMainThread(_ block: @escaping () -> Void) {
DispatchQueue.main.async(execute: block) DispatchQueue.main.async(execute: block)
} }
/// EZSE: Runs in Default priority queue /// EZSE: Runs in Default priority queue
public static func runThisInBackground(_ block: @escaping () -> ()) { public static func runThisInBackground(_ block: @escaping () -> Void) {
DispatchQueue.global(qos: .default).async(execute: block) DispatchQueue.global(qos: .default).async(execute: block)
} }

View File

@ -200,11 +200,9 @@ extension String {
/// EZSE: Checks if string is empty or consists only of whitespace and newline characters /// EZSE: Checks if string is empty or consists only of whitespace and newline characters
public var isBlank: Bool { public var isBlank: Bool {
get {
let trimmed = trimmingCharacters(in: .whitespacesAndNewlines) let trimmed = trimmingCharacters(in: .whitespacesAndNewlines)
return trimmed.isEmpty return trimmed.isEmpty
} }
}
/// EZSE: Trims white space and new line characters /// EZSE: Trims white space and new line characters
public mutating func trim() { public mutating func trim() {
@ -366,7 +364,7 @@ extension String {
} }
/// EZSE: Converts String to NSString /// EZSE: Converts String to NSString
public var toNSString: NSString { get { return self as NSString } } public var toNSString: NSString { return self as NSString }
#if os(iOS) #if os(iOS)

View File

@ -17,13 +17,13 @@ extension Timer {
} }
/// EZSE: Run function after x seconds /// EZSE: Run function after x seconds
public static func runThisAfterDelay(seconds: Double, after: @escaping () -> ()) { public static func runThisAfterDelay(seconds: Double, after: @escaping () -> Void) {
runThisAfterDelay(seconds: seconds, queue: DispatchQueue.main, after: after) runThisAfterDelay(seconds: seconds, queue: DispatchQueue.main, after: after)
} }
//TODO: Make this easier //TODO: Make this easier
/// EZSwiftExtensions - dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0) /// EZSwiftExtensions - dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)
public static func runThisAfterDelay(seconds: Double, queue: DispatchQueue, after: @escaping ()->()) { public static func runThisAfterDelay(seconds: Double, queue: DispatchQueue, after: @escaping () -> Void) {
let time = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) let time = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
queue.asyncAfter(deadline: time, execute: after) queue.asyncAfter(deadline: time, execute: after)
} }

View File

@ -6,7 +6,6 @@
// Copyright (c) 2015 Goktug Yilmaz. All rights reserved. // Copyright (c) 2015 Goktug Yilmaz. All rights reserved.
// swiftlint:disable trailing_whitespace // swiftlint:disable trailing_whitespace
import UIKit import UIKit
extension UIViewController { extension UIViewController {
@ -27,7 +26,6 @@ extension UIViewController {
NotificationCenter.default.removeObserver(self) NotificationCenter.default.removeObserver(self)
} }
#if os(iOS) #if os(iOS)
///EZSE: Adds a NotificationCenter Observer for keyboardWillShowNotification() ///EZSE: Adds a NotificationCenter Observer for keyboardWillShowNotification()
@ -78,7 +76,6 @@ extension UIViewController {
self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidHide.rawValue) self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidHide.rawValue)
} }
public func keyboardDidShowNotification(_ notification: Notification) { public func keyboardDidShowNotification(_ notification: Notification) {
if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue { if let nInfo = (notification as NSNotification).userInfo, let value = nInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue {
@ -150,7 +147,6 @@ extension UIViewController {
///EZSE: Returns maximum y of the ViewController ///EZSE: Returns maximum y of the ViewController
public var top: CGFloat { public var top: CGFloat {
get {
if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController { if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController {
return visibleViewController.top return visibleViewController.top
} }
@ -164,11 +160,9 @@ extension UIViewController {
return view.top return view.top
} }
} }
}
///EZSE: Returns minimum y of the ViewController ///EZSE: Returns minimum y of the ViewController
public var bottom: CGFloat { public var bottom: CGFloat {
get {
if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController { if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController {
return visibleViewController.bottom return visibleViewController.bottom
} }
@ -182,11 +176,9 @@ extension UIViewController {
return view.bottom return view.bottom
} }
} }
}
///EZSE: Returns Tab Bar's height ///EZSE: Returns Tab Bar's height
public var tabBarHeight: CGFloat { public var tabBarHeight: CGFloat {
get {
if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController { if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController {
return visibleViewController.tabBarHeight return visibleViewController.tabBarHeight
} }
@ -195,11 +187,9 @@ extension UIViewController {
} }
return 0 return 0
} }
}
///EZSE: Returns Navigation Bar's height ///EZSE: Returns Navigation Bar's height
public var navigationBarHeight: CGFloat { public var navigationBarHeight: CGFloat {
get {
if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController { if let me = self as? UINavigationController, let visibleViewController = me.visibleViewController {
return visibleViewController.navigationBarHeight return visibleViewController.navigationBarHeight
} }
@ -208,7 +198,6 @@ extension UIViewController {
} }
return 0 return 0
} }
}
///EZSE: Returns Navigation Bar's color ///EZSE: Returns Navigation Bar's color
public var navigationBarColor: UIColor? { public var navigationBarColor: UIColor? {
@ -224,17 +213,13 @@ extension UIViewController {
///EZSE: Returns current Navigation Bar ///EZSE: Returns current Navigation Bar
public var navBar: UINavigationBar? { public var navBar: UINavigationBar? {
get {
return navigationController?.navigationBar return navigationController?.navigationBar
} }
}
/// EZSwiftExtensions /// EZSwiftExtensions
public var applicationFrame: CGRect { public var applicationFrame: CGRect {
get {
return CGRect(x: view.x, y: top, width: view.w, height: bottom - top) return CGRect(x: view.x, y: top, width: view.w, height: bottom - top)
} }
}
// MARK: - VC Flow // MARK: - VC Flow

View File

@ -476,7 +476,7 @@ extension UIView {
} }
/// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
public func addTapGesture(tapNumber: Int = 1, action: ((UITapGestureRecognizer) -> ())?) { public func addTapGesture(tapNumber: Int = 1, action: ((UITapGestureRecognizer) -> Void)?) {
let tap = BlockTap(tapCount: tapNumber, fingerCount: 1, action: action) let tap = BlockTap(tapCount: tapNumber, fingerCount: 1, action: action)
addGestureRecognizer(tap) addGestureRecognizer(tap)
isUserInteractionEnabled = true isUserInteractionEnabled = true
@ -498,7 +498,7 @@ extension UIView {
} }
/// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
public func addSwipeGesture(direction: UISwipeGestureRecognizerDirection, numberOfTouches: Int = 1, action: ((UISwipeGestureRecognizer) -> ())?) { public func addSwipeGesture(direction: UISwipeGestureRecognizerDirection, numberOfTouches: Int = 1, action: ((UISwipeGestureRecognizer) -> Void)?) {
let swipe = BlockSwipe(direction: direction, fingerCount: numberOfTouches, action: action) let swipe = BlockSwipe(direction: direction, fingerCount: numberOfTouches, action: action)
addGestureRecognizer(swipe) addGestureRecognizer(swipe)
isUserInteractionEnabled = true isUserInteractionEnabled = true
@ -512,7 +512,7 @@ extension UIView {
} }
/// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
public func addPanGesture(action: ((UIPanGestureRecognizer) -> ())?) { public func addPanGesture(action: ((UIPanGestureRecognizer) -> Void)?) {
let pan = BlockPan(action: action) let pan = BlockPan(action: action)
addGestureRecognizer(pan) addGestureRecognizer(pan)
isUserInteractionEnabled = true isUserInteractionEnabled = true
@ -532,7 +532,7 @@ extension UIView {
#if os(iOS) #if os(iOS)
/// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
public func addPinchGesture(action: ((UIPinchGestureRecognizer) -> ())?) { public func addPinchGesture(action: ((UIPinchGestureRecognizer) -> Void)?) {
let pinch = BlockPinch(action: action) let pinch = BlockPinch(action: action)
addGestureRecognizer(pinch) addGestureRecognizer(pinch)
isUserInteractionEnabled = true isUserInteractionEnabled = true
@ -548,7 +548,7 @@ extension UIView {
} }
/// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak /// EZSwiftExtensions - Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
public func addLongPressGesture(action: ((UILongPressGestureRecognizer) -> ())?) { public func addLongPressGesture(action: ((UILongPressGestureRecognizer) -> Void)?) {
let longPress = BlockLongPress(action: action) let longPress = BlockLongPress(action: action)
addGestureRecognizer(longPress) addGestureRecognizer(longPress)
isUserInteractionEnabled = true isUserInteractionEnabled = true