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 {
@ -25,48 +25,48 @@ extension String {
} }
return nil return nil
} }
/// EZSE: base64 encoded of string /// EZSE: base64 encoded of string
var base64: String { var base64: String {
let plainData = (self as NSString).data(using: String.Encoding.utf8.rawValue) let plainData = (self as NSString).data(using: String.Encoding.utf8.rawValue)
let base64String = plainData!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0)) let base64String = plainData!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
return base64String return base64String
} }
/// EZSE: Cut string from integerIndex to the end /// EZSE: Cut string from integerIndex to the end
public subscript(integerIndex: Int) -> Character { public subscript(integerIndex: Int) -> Character {
let index = characters.index(startIndex, offsetBy: integerIndex) let index = characters.index(startIndex, offsetBy: integerIndex)
return self[index] return self[index]
} }
/// EZSE: Cut string from range /// EZSE: Cut string from range
public subscript(integerRange: Range<Int>) -> String { public subscript(integerRange: Range<Int>) -> String {
let start = characters.index(startIndex, offsetBy: integerRange.lowerBound) let start = characters.index(startIndex, offsetBy: integerRange.lowerBound)
let end = characters.index(startIndex, offsetBy: integerRange.upperBound) let end = characters.index(startIndex, offsetBy: integerRange.upperBound)
return self[start..<end] return self[start..<end]
} }
/// EZSE: Cut string from closedrange /// EZSE: Cut string from closedrange
public subscript(integerClosedRange: ClosedRange<Int>) -> String { public subscript(integerClosedRange: ClosedRange<Int>) -> String {
return self[integerClosedRange.lowerBound..<(integerClosedRange.upperBound + 1)] return self[integerClosedRange.lowerBound..<(integerClosedRange.upperBound + 1)]
} }
/// EZSE: Character count /// EZSE: Character count
public var length: Int { public var length: Int {
return self.characters.count return self.characters.count
} }
/// EZSE: Counts number of instances of the input inside String /// EZSE: Counts number of instances of the input inside String
public func count(_ substring: String) -> Int { public func count(_ substring: String) -> Int {
return components(separatedBy: substring).count - 1 return components(separatedBy: substring).count - 1
} }
/// EZSE: Capitalizes first character of String /// EZSE: Capitalizes first character of String
public mutating func capitalizeFirst() { public mutating func capitalizeFirst() {
guard characters.count > 0 else { return } guard characters.count > 0 else { return }
self.replaceSubrange(startIndex...startIndex, with: String(self[startIndex]).capitalized) self.replaceSubrange(startIndex...startIndex, with: String(self[startIndex]).capitalized)
} }
/// EZSE: Capitalizes first character of String, returns a new string /// EZSE: Capitalizes first character of String, returns a new string
public func capitalizedFirst() -> String { public func capitalizedFirst() -> String {
guard characters.count > 0 else { return self } guard characters.count > 0 else { return self }
@ -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,22 +200,20 @@ 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
public func trimmed() -> String { public func trimmed() -> String {
return self.trimmingCharacters(in: .whitespacesAndNewlines) return self.trimmingCharacters(in: .whitespacesAndNewlines)
} }
/// EZSE: Position of begining character of substing /// EZSE: Position of begining character of substing
public func positionOfSubstring(_ subString: String, caseInsensitive: Bool = false, fromEnd: Bool = false) -> Int { public func positionOfSubstring(_ subString: String, caseInsensitive: Bool = false, fromEnd: Bool = false) -> Int {
if subString.isEmpty { if subString.isEmpty {
@ -230,34 +228,34 @@ extension String {
} }
return -1 return -1
} }
/// EZSE: split string using a spearator string, returns an array of string /// EZSE: split string using a spearator string, returns an array of string
public func split(_ separator: String) -> [String] { public func split(_ separator: String) -> [String] {
return self.components(separatedBy: separator).filter { return self.components(separatedBy: separator).filter {
!$0.trimmed().isEmpty !$0.trimmed().isEmpty
} }
} }
/// EZSE: split string with delimiters, returns an array of string /// EZSE: split string with delimiters, returns an array of string
public func split(_ characters: CharacterSet) -> [String] { public func split(_ characters: CharacterSet) -> [String] {
return self.components(separatedBy: characters).filter { return self.components(separatedBy: characters).filter {
!$0.trimmed().isEmpty !$0.trimmed().isEmpty
} }
} }
/// EZSE : Returns count of words in string /// EZSE : Returns count of words in string
public var countofWords: Int { public var countofWords: Int {
let regex = try? NSRegularExpression(pattern: "\\w+", options: NSRegularExpression.Options()) let regex = try? NSRegularExpression(pattern: "\\w+", options: NSRegularExpression.Options())
return regex?.numberOfMatches(in: self, options: NSRegularExpression.MatchingOptions(), range: NSRange(location: 0, length: self.length)) ?? 0 return regex?.numberOfMatches(in: self, options: NSRegularExpression.MatchingOptions(), range: NSRange(location: 0, length: self.length)) ?? 0
} }
/// EZSE : Returns count of paragraphs in string /// EZSE : Returns count of paragraphs in string
public var countofParagraphs: Int { public var countofParagraphs: Int {
let regex = try? NSRegularExpression(pattern: "\\n", options: NSRegularExpression.Options()) let regex = try? NSRegularExpression(pattern: "\\n", options: NSRegularExpression.Options())
let str = self.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) let str = self.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
return (regex?.numberOfMatches(in: str, options: NSRegularExpression.MatchingOptions(), range: NSRange(location:0, length: str.length)) ?? -1) + 1 return (regex?.numberOfMatches(in: str, options: NSRegularExpression.MatchingOptions(), range: NSRange(location:0, length: str.length)) ?? -1) + 1
} }
internal func rangeFromNSRange(_ nsRange: NSRange) -> Range<String.Index>? { internal func rangeFromNSRange(_ nsRange: NSRange) -> Range<String.Index>? {
let from16 = utf16.startIndex.advanced(by: nsRange.location) let from16 = utf16.startIndex.advanced(by: nsRange.location)
let to16 = from16.advanced(by: nsRange.length) let to16 = from16.advanced(by: nsRange.length)
@ -267,21 +265,21 @@ extension String {
} }
return nil return nil
} }
/// EZSE: Find matches of regular expression in string /// EZSE: Find matches of regular expression in string
public func matchesForRegexInText(_ regex: String!) -> [String] { public func matchesForRegexInText(_ regex: String!) -> [String] {
let regex = try? NSRegularExpression(pattern: regex, options: []) let regex = try? NSRegularExpression(pattern: regex, options: [])
let results = regex?.matches(in: self, options: [], range: NSRange(location: 0, length: self.length)) ?? [] let results = regex?.matches(in: self, options: [], range: NSRange(location: 0, length: self.length)) ?? []
return results.map { self.substring(with: self.rangeFromNSRange($0.range)!) } return results.map { self.substring(with: self.rangeFromNSRange($0.range)!) }
} }
/// EZSE: Checks if String contains Email /// EZSE: Checks if String contains Email
public var isEmail: Bool { public var isEmail: Bool {
let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
let firstMatch = dataDetector?.firstMatch(in: self, options: NSRegularExpression.MatchingOptions.reportCompletion, range: NSRange(location: 0, length: length)) let firstMatch = dataDetector?.firstMatch(in: self, options: NSRegularExpression.MatchingOptions.reportCompletion, range: NSRange(location: 0, length: length))
return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto") return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto")
} }
/// EZSE: Returns if String is a number /// EZSE: Returns if String is a number
public func isNumber() -> Bool { public func isNumber() -> Bool {
if let _ = NumberFormatter().number(from: self) { if let _ = NumberFormatter().number(from: self) {
@ -289,7 +287,7 @@ extension String {
} }
return false return false
} }
/// EZSE: Extracts URLS from String /// EZSE: Extracts URLS from String
public var extractURLs: [URL] { public var extractURLs: [URL] {
var urls: [URL] = [] var urls: [URL] = []
@ -299,9 +297,9 @@ extension String {
} catch _ as NSError { } catch _ as NSError {
detector = nil detector = nil
} }
let text = self let text = self
if let detector = detector { if let detector = detector {
detector.enumerateMatches(in: text, options: [], range: NSRange(location: 0, length: text.characters.count), using: { detector.enumerateMatches(in: text, options: [], range: NSRange(location: 0, length: text.characters.count), using: {
(result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in (result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
@ -310,15 +308,15 @@ extension String {
} }
}) })
} }
return urls return urls
} }
/// EZSE: Checking if String contains input with comparing options /// EZSE: Checking if String contains input with comparing options
public func contains(_ find: String, compareOption: NSString.CompareOptions) -> Bool { public func contains(_ find: String, compareOption: NSString.CompareOptions) -> Bool {
return self.range(of: find, options: compareOption) != nil return self.range(of: find, options: compareOption) != nil
} }
/// EZSE: Converts String to Int /// EZSE: Converts String to Int
public func toInt() -> Int? { public func toInt() -> Int? {
if let num = NumberFormatter().number(from: self) { if let num = NumberFormatter().number(from: self) {
@ -327,7 +325,7 @@ extension String {
return nil return nil
} }
} }
/// EZSE: Converts String to Double /// EZSE: Converts String to Double
public func toDouble() -> Double? { public func toDouble() -> Double? {
if let num = NumberFormatter().number(from: self) { if let num = NumberFormatter().number(from: self) {
@ -336,7 +334,7 @@ extension String {
return nil return nil
} }
} }
/// EZSE: Converts String to Float /// EZSE: Converts String to Float
public func toFloat() -> Float? { public func toFloat() -> Float? {
if let num = NumberFormatter().number(from: self) { if let num = NumberFormatter().number(from: self) {
@ -345,7 +343,7 @@ extension String {
return nil return nil
} }
} }
/// EZSE: Converts String to Bool /// EZSE: Converts String to Bool
public func toBool() -> Bool? { public func toBool() -> Bool? {
let trimmedString = trimmed().lowercased() let trimmedString = trimmed().lowercased()
@ -354,7 +352,7 @@ extension String {
} }
return nil return nil
} }
///EZSE: Returns the first index of the occurency of the character in String ///EZSE: Returns the first index of the occurency of the character in String
public func getIndexOf(_ char: Character) -> Int? { public func getIndexOf(_ char: Character) -> Int? {
for (index, c) in characters.enumerated() { for (index, c) in characters.enumerated() {
@ -364,10 +362,10 @@ extension String {
} }
return nil return nil
} }
/// 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)
///EZSE: Returns bold NSAttributedString ///EZSE: Returns bold NSAttributedString
@ -377,7 +375,7 @@ extension String {
} }
#endif #endif
///EZSE: Returns underlined NSAttributedString ///EZSE: Returns underlined NSAttributedString
public func underline() -> NSAttributedString { public func underline() -> NSAttributedString {
let underlineString = NSAttributedString(string: self, attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue]) let underlineString = NSAttributedString(string: self, attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue])
@ -385,7 +383,7 @@ extension String {
} }
#if os(iOS) #if os(iOS)
///EZSE: Returns italic NSAttributedString ///EZSE: Returns italic NSAttributedString
public func italic() -> NSAttributedString { public func italic() -> NSAttributedString {
let italicString = NSMutableAttributedString(string: self, attributes: [NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)]) let italicString = NSMutableAttributedString(string: self, attributes: [NSFontAttributeName: UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)])
@ -393,9 +391,9 @@ extension String {
} }
#endif #endif
#if os(iOS) #if os(iOS)
///EZSE: Returns hight of rendered string ///EZSE: Returns hight of rendered string
func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat { func height(_ width: CGFloat, font: UIFont, lineBreakMode: NSLineBreakMode?) -> CGFloat {
var attrib: [String: AnyObject] = [NSFontAttributeName: font] var attrib: [String: AnyObject] = [NSFontAttributeName: font]
@ -409,13 +407,13 @@ extension String {
} }
#endif #endif
///EZSE: Returns NSAttributedString ///EZSE: Returns NSAttributedString
public func color(_ color: UIColor) -> NSAttributedString { public func color(_ color: UIColor) -> NSAttributedString {
let colorString = NSMutableAttributedString(string: self, attributes: [NSForegroundColorAttributeName: color]) let colorString = NSMutableAttributedString(string: self, attributes: [NSForegroundColorAttributeName: color])
return colorString return colorString
} }
///EZSE: Returns NSAttributedString ///EZSE: Returns NSAttributedString
public func colorSubString(_ subString: String, color: UIColor) -> NSMutableAttributedString { public func colorSubString(_ subString: String, color: UIColor) -> NSMutableAttributedString {
var start = 0 var start = 0
@ -435,7 +433,7 @@ extension String {
} }
return attrText return attrText
} }
/// EZSE: Checks if String contains Emoji /// EZSE: Checks if String contains Emoji
public func includesEmoji() -> Bool { public func includesEmoji() -> Bool {
for i in 0...length { for i in 0...length {
@ -448,9 +446,9 @@ 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
} }
@ -485,7 +483,7 @@ extension String {
nFormatter.maximumFractionDigits = precision nFormatter.maximumFractionDigits = precision
self = nFormatter.string(from: NSNumber(value: value))! self = nFormatter.string(from: NSNumber(value: value))!
} }
init(_ value: Double, precision: Int) { init(_ value: Double, precision: Int) {
let nFormatter = NumberFormatter() let nFormatter = NumberFormatter()
nFormatter.numberStyle = .decimal nFormatter.numberStyle = .decimal

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,30 +6,28 @@
// 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 {
// MARK: - Notifications // MARK: - Notifications
///EZSE: Adds an NotificationCenter with name and Selector ///EZSE: Adds an NotificationCenter with name and Selector
public func addNotificationObserver(_ name: String, selector: Selector) { public func addNotificationObserver(_ name: String, selector: Selector) {
NotificationCenter.default.addObserver(self, selector: selector, name: NSNotification.Name(rawValue: name), object: nil) NotificationCenter.default.addObserver(self, selector: selector, name: NSNotification.Name(rawValue: name), object: nil)
} }
///EZSE: Removes an NSNotificationCenter for name ///EZSE: Removes an NSNotificationCenter for name
public func removeNotificationObserver(_ name: String) { public func removeNotificationObserver(_ name: String) {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: name), object: nil) NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: name), object: nil)
} }
///EZSE: Removes NotificationCenter'd observer ///EZSE: Removes NotificationCenter'd observer
public func removeNotificationObserver() { public func removeNotificationObserver() {
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()
/// ///
/// You also need to implement ```keyboardWillShowNotification(_ notification: Notification)``` /// You also need to implement ```keyboardWillShowNotification(_ notification: Notification)```
@ -43,14 +41,14 @@ extension UIViewController {
public func addKeyboardDidShowNotification() { public func addKeyboardDidShowNotification() {
self.addNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue, selector: #selector(UIViewController.keyboardDidShowNotification(_:))) self.addNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue, selector: #selector(UIViewController.keyboardDidShowNotification(_:)))
} }
///EZSE: Adds a NotificationCenter Observer for keyboardWillHideNotification() ///EZSE: Adds a NotificationCenter Observer for keyboardWillHideNotification()
/// ///
/// You also need to implement ```keyboardWillHideNotification(_ notification: Notification)``` /// You also need to implement ```keyboardWillHideNotification(_ notification: Notification)```
public func addKeyboardWillHideNotification() { public func addKeyboardWillHideNotification() {
self.addNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue, selector: #selector(UIViewController.keyboardWillHideNotification(_:))) self.addNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue, selector: #selector(UIViewController.keyboardWillHideNotification(_:)))
} }
///EZSE: Adds a NotificationCenter Observer for keyboardDidHideNotification() ///EZSE: Adds a NotificationCenter Observer for keyboardDidHideNotification()
/// ///
/// You also need to implement ```keyboardDidHideNotification(_ notification: Notification)``` /// You also need to implement ```keyboardDidHideNotification(_ notification: Notification)```
@ -62,154 +60,145 @@ extension UIViewController {
public func removeKeyboardWillShowNotification() { public func removeKeyboardWillShowNotification() {
self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillShow.rawValue) self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillShow.rawValue)
} }
///EZSE: Removes keyboardDidShowNotification()'s NotificationCenter Observer ///EZSE: Removes keyboardDidShowNotification()'s NotificationCenter Observer
public func removeKeyboardDidShowNotification() { public func removeKeyboardDidShowNotification() {
self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue) self.removeNotificationObserver(NSNotification.Name.UIKeyboardDidShow.rawValue)
} }
///EZSE: Removes keyboardWillHideNotification()'s NotificationCenter Observer ///EZSE: Removes keyboardWillHideNotification()'s NotificationCenter Observer
public func removeKeyboardWillHideNotification() { public func removeKeyboardWillHideNotification() {
self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue) self.removeNotificationObserver(NSNotification.Name.UIKeyboardWillHide.rawValue)
} }
///EZSE: Removes keyboardDidHideNotification()'s NotificationCenter Observer ///EZSE: Removes keyboardDidHideNotification()'s NotificationCenter Observer
public func removeKeyboardDidHideNotification() { public func removeKeyboardDidHideNotification() {
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 {
let frame = value.cgRectValue let frame = value.cgRectValue
keyboardDidShowWithFrame(frame) keyboardDidShowWithFrame(frame)
} }
} }
public func keyboardWillShowNotification(_ notification: Notification) { public func keyboardWillShowNotification(_ 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 {
let frame = value.cgRectValue let frame = value.cgRectValue
keyboardWillShowWithFrame(frame) keyboardWillShowWithFrame(frame)
} }
} }
public func keyboardWillHideNotification(_ notification: Notification) { public func keyboardWillHideNotification(_ 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 {
let frame = value.cgRectValue let frame = value.cgRectValue
keyboardWillHideWithFrame(frame) keyboardWillHideWithFrame(frame)
} }
} }
public func keyboardDidHideNotification(_ notification: Notification) { public func keyboardDidHideNotification(_ 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 {
let frame = value.cgRectValue let frame = value.cgRectValue
keyboardDidHideWithFrame(frame) keyboardDidHideWithFrame(frame)
} }
} }
public func keyboardWillShowWithFrame(_ frame: CGRect) { public func keyboardWillShowWithFrame(_ frame: CGRect) {
} }
public func keyboardDidShowWithFrame(_ frame: CGRect) { public func keyboardDidShowWithFrame(_ frame: CGRect) {
} }
public func keyboardWillHideWithFrame(_ frame: CGRect) { public func keyboardWillHideWithFrame(_ frame: CGRect) {
} }
public func keyboardDidHideWithFrame(_ frame: CGRect) { public func keyboardDidHideWithFrame(_ frame: CGRect) {
} }
//EZSE: Makes the UIViewController register tap events and hides keyboard when clicked somewhere in the ViewController. //EZSE: Makes the UIViewController register tap events and hides keyboard when clicked somewhere in the ViewController.
public func hideKeyboardWhenTappedAround() { public func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap) view.addGestureRecognizer(tap)
} }
public func hideKeyboardWhenTappedAroundAndCancelsTouchesInView() { public func hideKeyboardWhenTappedAroundAndCancelsTouchesInView() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap) view.addGestureRecognizer(tap)
} }
#endif #endif
//EZSE: Dismisses keyboard //EZSE: Dismisses keyboard
public func dismissKeyboard() { public func dismissKeyboard() {
view.endEditing(true) view.endEditing(true)
} }
// MARK: - VC Container // MARK: - VC Container
///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
public var navigationBarColor: UIColor? { public var navigationBarColor: UIColor? {
get { get {
@ -221,28 +210,24 @@ extension UIViewController {
navigationController?.navigationBar.barTintColor = value navigationController?.navigationBar.barTintColor = value
} }
} }
///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
///EZSE: Pushes a view controller onto the receivers stack and updates the display. ///EZSE: Pushes a view controller onto the receivers stack and updates the display.
public func pushVC(_ vc: UIViewController) { public func pushVC(_ vc: UIViewController) {
navigationController?.pushViewController(vc, animated: true) navigationController?.pushViewController(vc, animated: true)
} }
///EZSE: Pops the top view controller from the navigation stack and updates the display. ///EZSE: Pops the top view controller from the navigation stack and updates the display.
public func popVC() { public func popVC() {
_ = navigationController?.popViewController(animated: true) _ = navigationController?.popViewController(animated: true)
@ -257,19 +242,19 @@ extension UIViewController {
public func presentVC(_ vc: UIViewController) { public func presentVC(_ vc: UIViewController) {
present(vc, animated: true, completion: nil) present(vc, animated: true, completion: nil)
} }
///EZSE: Dismisses the view controller that was presented modally by the view controller. ///EZSE: Dismisses the view controller that was presented modally by the view controller.
public func dismissVC(completion: (() -> Void)? ) { public func dismissVC(completion: (() -> Void)? ) {
dismiss(animated: true, completion: completion) dismiss(animated: true, completion: completion)
} }
///EZSE: Adds the specified view controller as a child of the current view controller. ///EZSE: Adds the specified view controller as a child of the current view controller.
public func addAsChildViewController(_ vc: UIViewController, toView: UIView) { public func addAsChildViewController(_ vc: UIViewController, toView: UIView) {
self.addChildViewController(vc) self.addChildViewController(vc)
toView.addSubview(vc.view) toView.addSubview(vc.view)
vc.didMove(toParentViewController: self) vc.didMove(toParentViewController: self)
} }
///EZSE: Adds image named: as a UIImageView in the Background ///EZSE: Adds image named: as a UIImageView in the Background
public func setBackgroundImage(_ named: String) { public func setBackgroundImage(_ named: String) {
let image = UIImage(named: named) let image = UIImage(named: named)
@ -278,7 +263,7 @@ extension UIViewController {
view.addSubview(imageView) view.addSubview(imageView)
view.sendSubview(toBack: imageView) view.sendSubview(toBack: imageView)
} }
///EZSE: Adds UIImage as a UIImageView in the Background ///EZSE: Adds UIImage as a UIImageView in the Background
@nonobjc func setBackgroundImage(_ image: UIImage) { @nonobjc func setBackgroundImage(_ image: UIImage) {
let imageView = UIImageView(frame: view.frame) let imageView = UIImageView(frame: view.frame)

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