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)
} }
@ -201,7 +201,7 @@ extension Array where Element: Equatable {
} }
} }
//MARK: - Deprecated 1.8 // MARK: - Deprecated 1.8
extension Array { extension Array {
@ -241,13 +241,13 @@ extension Array where Element: Equatable {
} }
//MARK: - Deprecated 1.7 // MARK: - Deprecated 1.7
extension Array { 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)
} }
@ -287,13 +287,13 @@ extension Array where Element: Equatable {
} }
//MARK: - Deprecated 1.6 // MARK: - Deprecated 1.6
extension Array { 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

@ -51,7 +51,7 @@ extension CGRect {
} }
/// EZSE : Surface Area represented by a CGRectangle /// EZSE : Surface Area represented by a CGRectangle
public var area : CGFloat { public var area: CGFloat {
return self.h * self.w return self.h * self.w
} }
} }

View File

@ -18,18 +18,14 @@ 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

View File

@ -200,7 +200,7 @@ extension Date {
} }
/// EZSE : Gets the nano second from the date /// EZSE : Gets the nano second from the date
public var nanosecond : Int { public var nanosecond: Int {
return Calendar.current.component(.nanosecond, from: self) return Calendar.current.component(.nanosecond, from: self)
} }
} }

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

@ -16,7 +16,7 @@ extension Double {
public var toInt: Int { return Int(self) } public var toInt: Int { return Int(self) }
} }
//MARK: - Deprecated 1.8 // MARK: - Deprecated 1.8
extension Double { extension Double {
@ -45,8 +45,8 @@ 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

@ -59,7 +59,7 @@ extension UInt {
/// EZSE: Greatest common divisor of two integers using the Euclid's algorithm. /// EZSE: Greatest common divisor of two integers using the Euclid's algorithm.
/// Time complexity of this in O(log(n)) /// Time complexity of this in O(log(n))
public static func gcd(_ firstNum:UInt, _ secondNum:UInt) -> UInt { public static func gcd(_ firstNum: UInt, _ secondNum: UInt) -> UInt {
let remainder = firstNum % secondNum let remainder = firstNum % secondNum
if remainder != 0 { if remainder != 0 {
return gcd(secondNum, remainder) return gcd(secondNum, remainder)
@ -69,7 +69,7 @@ extension UInt {
} }
/// EZSE: Least common multiple of two numbers. LCM = n * m / gcd(n, m) /// EZSE: Least common multiple of two numbers. LCM = n * m / gcd(n, m)
public static func lcm(_ firstNum:UInt, _ secondNum:UInt) -> UInt { public static func lcm(_ firstNum: UInt, _ secondNum: UInt) -> UInt {
return firstNum * secondNum / UInt.gcd(firstNum, secondNum) return firstNum * secondNum / UInt.gcd(firstNum, secondNum)
} }
} }

View File

@ -11,7 +11,7 @@ import Foundation
public extension NSDictionary { public extension NSDictionary {
//MARK: - Deprecated 1.8 // MARK: - Deprecated 1.8
/// EZSE: Unserialize JSON string into NSDictionary /// EZSE: Unserialize JSON string into NSDictionary
@available(*, deprecated: 1.8) @available(*, deprecated: 1.8)

View File

@ -9,9 +9,9 @@
// swiftlint:disable trailing_whitespace // swiftlint:disable trailing_whitespace
#if os(OSX) #if os(OSX)
import AppKit import AppKit
#else #else
import UIKit import UIKit
#endif #endif
extension String { extension String {
@ -88,7 +88,7 @@ extension String {
guard characters.count > 0 && count > 0 else { return self } guard characters.count > 0 && count > 0 else { return self }
var result = self var result = self
result.replaceSubrange(startIndex..<self.index(startIndex, offsetBy: min(count, length)), result.replaceSubrange(startIndex..<self.index(startIndex, offsetBy: min(count, length)),
with: String(self[startIndex..<self.index(startIndex, offsetBy: min(count, length))]).uppercased()) with: String(self[startIndex..<self.index(startIndex, offsetBy: min(count, length))]).uppercased())
return result return result
} }
@ -96,7 +96,7 @@ extension String {
public mutating func uppercaseSuffix(_ count: Int) { public mutating func uppercaseSuffix(_ count: Int) {
guard characters.count > 0 && count > 0 else { return } guard characters.count > 0 && count > 0 else { return }
self.replaceSubrange(self.index(endIndex, offsetBy: -min(count, length))..<endIndex, self.replaceSubrange(self.index(endIndex, offsetBy: -min(count, length))..<endIndex,
with: String(self[self.index(endIndex, offsetBy: -min(count, length))..<endIndex]).uppercased()) with: String(self[self.index(endIndex, offsetBy: -min(count, length))..<endIndex]).uppercased())
} }
/// EZSE: Uppercases last 'count' characters of String, returns a new string /// EZSE: Uppercases last 'count' characters of String, returns a new string
@ -104,7 +104,7 @@ extension String {
guard characters.count > 0 && count > 0 else { return self } guard characters.count > 0 && count > 0 else { return self }
var result = self var result = self
result.replaceSubrange(characters.index(endIndex, offsetBy: -min(count, length))..<endIndex, result.replaceSubrange(characters.index(endIndex, offsetBy: -min(count, length))..<endIndex,
with: String(self[characters.index(endIndex, offsetBy: -min(count, length))..<endIndex]).uppercased()) with: String(self[characters.index(endIndex, offsetBy: -min(count, length))..<endIndex]).uppercased())
return result return result
} }
@ -122,7 +122,7 @@ extension String {
guard characters.count > 0 && (0..<length).contains(from) else { return self } guard characters.count > 0 && (0..<length).contains(from) else { return self }
var result = self var result = self
result.replaceSubrange(characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to), result.replaceSubrange(characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to),
with: String(self[characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to)]).uppercased()) with: String(self[characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to)]).uppercased())
return result return result
} }
@ -144,7 +144,7 @@ extension String {
public mutating func lowercasePrefix(_ count: Int) { public mutating func lowercasePrefix(_ count: Int) {
guard characters.count > 0 && count > 0 else { return } guard characters.count > 0 && count > 0 else { return }
self.replaceSubrange(startIndex..<self.index(startIndex, offsetBy: min(count, length)), self.replaceSubrange(startIndex..<self.index(startIndex, offsetBy: min(count, length)),
with: String(self[startIndex..<self.index(startIndex, offsetBy: min(count, length))]).lowercased()) with: String(self[startIndex..<self.index(startIndex, offsetBy: min(count, length))]).lowercased())
} }
/// EZSE: Lowercases first 'count' characters of String, returns a new string /// EZSE: Lowercases first 'count' characters of String, returns a new string
@ -152,7 +152,7 @@ extension String {
guard characters.count > 0 && count > 0 else { return self } guard characters.count > 0 && count > 0 else { return self }
var result = self var result = self
result.replaceSubrange(startIndex..<characters.index(startIndex, offsetBy: min(count, length)), result.replaceSubrange(startIndex..<characters.index(startIndex, offsetBy: min(count, length)),
with: String(self[startIndex..<characters.index(startIndex, offsetBy: min(count, length))]).lowercased()) with: String(self[startIndex..<characters.index(startIndex, offsetBy: min(count, length))]).lowercased())
return result return result
} }
@ -160,7 +160,7 @@ extension String {
public mutating func lowercaseSuffix(_ count: Int) { public mutating func lowercaseSuffix(_ count: Int) {
guard characters.count > 0 && count > 0 else { return } guard characters.count > 0 && count > 0 else { return }
self.replaceSubrange(self.index(endIndex, offsetBy: -min(count, length))..<endIndex, self.replaceSubrange(self.index(endIndex, offsetBy: -min(count, length))..<endIndex,
with: String(self[self.index(endIndex, offsetBy: -min(count, length))..<endIndex]).lowercased()) with: String(self[self.index(endIndex, offsetBy: -min(count, length))..<endIndex]).lowercased())
} }
/// EZSE: Lowercases last 'count' characters of String, returns a new string /// EZSE: Lowercases last 'count' characters of String, returns a new string
@ -168,7 +168,7 @@ extension String {
guard characters.count > 0 && count > 0 else { return self } guard characters.count > 0 && count > 0 else { return self }
var result = self var result = self
result.replaceSubrange(characters.index(endIndex, offsetBy: -min(count, length))..<endIndex, result.replaceSubrange(characters.index(endIndex, offsetBy: -min(count, length))..<endIndex,
with: String(self[characters.index(endIndex, offsetBy: -min(count, length))..<endIndex]).lowercased()) with: String(self[characters.index(endIndex, offsetBy: -min(count, length))..<endIndex]).lowercased())
return result return result
} }
@ -177,7 +177,7 @@ extension String {
let from = max(range.lowerBound, 0), to = min(range.upperBound, length) let from = max(range.lowerBound, 0), to = min(range.upperBound, length)
guard characters.count > 0 && (0..<length).contains(from) else { return } guard characters.count > 0 && (0..<length).contains(from) else { return }
self.replaceSubrange(self.index(startIndex, offsetBy: from)..<self.index(startIndex, offsetBy: to), self.replaceSubrange(self.index(startIndex, offsetBy: from)..<self.index(startIndex, offsetBy: to),
with: String(self[self.index(startIndex, offsetBy: from)..<self.index(startIndex, offsetBy: to)]).lowercased()) with: String(self[self.index(startIndex, offsetBy: from)..<self.index(startIndex, offsetBy: to)]).lowercased())
} }
/// EZSE: Lowercases string in range 'range' (from range.startIndex to range.endIndex), returns new string /// EZSE: Lowercases string in range 'range' (from range.startIndex to range.endIndex), returns new string
@ -186,7 +186,7 @@ extension String {
guard characters.count > 0 && (0..<length).contains(from) else { return self } guard characters.count > 0 && (0..<length).contains(from) else { return self }
var result = self var result = self
result.replaceSubrange(characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to), result.replaceSubrange(characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to),
with: String(self[characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to)]).lowercased()) with: String(self[characters.index(startIndex, offsetBy: from)..<characters.index(startIndex, offsetBy: to)]).lowercased())
return result return result
} }
@ -200,15 +200,13 @@ 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() {
self = self.trimmed() self = self.trimmed()
} }
/// EZSE: Trims white space and new line characters, returns a new string /// EZSE: Trims white space and new line characters, returns a new string
@ -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)
@ -450,7 +448,7 @@ extension String {
#if os(iOS) #if os(iOS)
/// EZSE: copy string to pasteboard /// EZSE: copy string to pasteboard
public func addToPasteboard() { public func addToPasteboard() {
let pasteboard = UIPasteboard.general let pasteboard = UIPasteboard.general
pasteboard.string = self pasteboard.string = self
} }

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

@ -12,7 +12,7 @@ import UIKit
private let DeviceList = [ private let DeviceList = [
/* iPod 5 */ "iPod5,1": "iPod Touch 5", /* iPod 5 */ "iPod5,1": "iPod Touch 5",
/* iPod 6 */ "iPod7,1": "iPod Touch 6", /* iPod 6 */ "iPod7,1": "iPod Touch 6",
/* iPhone 4 */ "iPhone3,1": "iPhone 4", "iPhone3,2": "iPhone 4", "iPhone3,3": "iPhone 4", /* iPhone 4 */ "iPhone3,1": "iPhone 4", "iPhone3,2": "iPhone 4", "iPhone3,3": "iPhone 4",
/* iPhone 4S */ "iPhone4,1": "iPhone 4S", /* iPhone 4S */ "iPhone4,1": "iPhone 4S",
/* iPhone 5 */ "iPhone5,1": "iPhone 5", "iPhone5,2": "iPhone 5", /* iPhone 5 */ "iPhone5,1": "iPhone 5", "iPhone5,2": "iPhone 5",
/* iPhone 5C */ "iPhone5,3": "iPhone 5C", "iPhone5,4": "iPhone 5C", /* iPhone 5C */ "iPhone5,3": "iPhone 5C", "iPhone5,4": "iPhone 5C",

View File

@ -91,7 +91,7 @@ extension UIFont {
return Font(.AvenirNext, type: .Regular, size: size) return Font(.AvenirNext, type: .Regular, size: size)
} }
//MARK: Deprecated // MARK: Deprecated
/// EZSwiftExtensions /// EZSwiftExtensions
@available(*, deprecated: 1.8) @available(*, deprecated: 1.8)

View File

@ -95,7 +95,7 @@ extension UIImageView {
} }
} }
//MARK: Deprecated 1.8 // MARK: Deprecated 1.8
/// EZSwiftExtensions /// EZSwiftExtensions
@available(*, deprecated: 1.8, renamed: "image(url:)") @available(*, deprecated: 1.8, renamed: "image(url:)")

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,64 +147,56 @@ 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 }
} if let nav = self.navigationController {
if let nav = self.navigationController { if nav.isNavigationBarHidden {
if nav.isNavigationBarHidden {
return view.top
} else {
return nav.navigationBar.bottom
}
} else {
return view.top return view.top
} else {
return nav.navigationBar.bottom
} }
} else {
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 }
} if let tab = tabBarController {
if let tab = tabBarController { if tab.tabBar.isHidden {
if tab.tabBar.isHidden {
return view.bottom
} else {
return tab.tabBar.top
}
} else {
return view.bottom return view.bottom
} else {
return tab.tabBar.top
} }
} else {
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
}
if let tab = self.tabBarController {
return tab.tabBar.frame.size.height
}
return 0
} }
if let tab = self.tabBarController {
return tab.tabBar.frame.size.height
}
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
}
if let nav = self.navigationController {
return nav.navigationBar.h
}
return 0
} }
if let nav = self.navigationController {
return nav.navigationBar.h
}
return 0
} }
///EZSE: Returns Navigation Bar's color ///EZSE: Returns Navigation Bar's color
@ -224,16 +213,12 @@ 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
@ -597,7 +597,7 @@ extension UIView {
} }
} }
//MARK: Fade Extensions // MARK: Fade Extensions
private let UIViewDefaultFadeDuration: TimeInterval = 0.4 private let UIViewDefaultFadeDuration: TimeInterval = 0.4