Skip to content

Commit

Permalink
Fixed almost all Swiftlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lfarah authored and Khalian committed Aug 25, 2017
1 parent e994b53 commit 3b7e548
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 38 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ disabled_rules:
- valid_docs
- todo
- variable_name_min_length
- trailing_whitespace
2 changes: 1 addition & 1 deletion EZSwiftExtensions/UIStackViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Kenza Iraki on 2017-03-12.
// Copyright © 2017 Goktug Yilmaz. All rights reserved.
//
// swiftlint:disable line_length

#if os(iOS) || os(tvOS)

Expand All @@ -13,7 +14,6 @@ import UIKit
@available(iOS 9.0, *)
extension UIStackView {


/// EZSwiftExtensions: Convenience initializer in order to directly pass the distribution, alignment, axis and spacing of the stack view.
///
/// - Parameters:
Expand Down
3 changes: 2 additions & 1 deletion Sources/BlockSwipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ open class BlockSwipe: UISwipeGestureRecognizer {
super.init(target: target, action: action)
}

public convenience init (direction: UISwipeGestureRecognizerDirection,
public convenience init (
direction: UISwipeGestureRecognizerDirection,
fingerCount: Int = 1,
action: ((UISwipeGestureRecognizer) -> Void)?) {
self.init()
Expand Down
1 change: 0 additions & 1 deletion Sources/CollectionsExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extension Collection {
return res
}


/// EZSE : Helper method to get an array of collection indices
private func indicesArray() -> [Self.Index] {
var indicesArray: [Self.Index] = []
Expand Down
5 changes: 4 additions & 1 deletion Sources/DictionaryExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ extension Dictionary {

/// EZSE: Unserialize JSON string into Dictionary
public static func constructFromJSON (json: String) -> Dictionary? {
if let data = (try? JSONSerialization.jsonObject(with: json.data(using: String.Encoding.utf8, allowLossyConversion: true)!, options: JSONSerialization.ReadingOptions.mutableContainers)) as? Dictionary {
if let data = (try? JSONSerialization.jsonObject(
with: json.data(using: String.Encoding.utf8,
allowLossyConversion: true)!,
options: JSONSerialization.ReadingOptions.mutableContainers)) as? Dictionary {
return data
} else {
return nil
Expand Down
11 changes: 7 additions & 4 deletions Sources/EZSwiftFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public struct ez {
/// EZSE: Calls action when a screen shot is taken
public static func detectScreenShot(_ action: @escaping () -> Void) {
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) { _ in
// executes after screenshot
action()
}
Expand Down Expand Up @@ -254,7 +254,10 @@ public struct ez {
}

/// EZSE: Runs every second, to cancel use: timer.invalidate()
@discardableResult public static func runThisEvery(seconds: TimeInterval, startAfterSeconds: TimeInterval, handler: @escaping (CFRunLoopTimer?) -> Void) -> Timer {
@discardableResult public static func runThisEvery(
seconds: TimeInterval,
startAfterSeconds: TimeInterval,
handler: @escaping (CFRunLoopTimer?) -> Void) -> Timer {
let fireDate = startAfterSeconds + CFAbsoluteTimeGetCurrent()
let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, seconds, 0, 0, handler)
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, CFRunLoopMode.commonModes)
Expand Down Expand Up @@ -341,7 +344,7 @@ public struct ez {
json = nil
}

if let _ = error {
if error != nil {
return nil
} else {
return json
Expand All @@ -360,7 +363,7 @@ public struct ez {

URLSession.shared.dataTask(
with: URLRequest(url: requestURL),
completionHandler: { data, response, err in
completionHandler: { data, _, err in
if let e = err {
error?(e as NSError)
} else {
Expand Down
12 changes: 4 additions & 8 deletions Sources/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright (c) 2015 Goktug Yilmaz. All rights reserved.
//
// swiftlint:disable line_length
// swiftlint:disable trailing_whitespace

#if os(OSX)
import AppKit
Expand Down Expand Up @@ -284,7 +283,7 @@ extension String {

/// EZSE: Returns if String is a number
public func isNumber() -> Bool {
if let _ = NumberFormatter().number(from: self) {
if NumberFormatter().number(from: self) != nil {
return true
}
return false
Expand All @@ -303,8 +302,7 @@ extension String {
let text = self

if let detector = detector {
detector.enumerateMatches(in: text, options: [], range: NSRange(location: 0, length: text.characters.count), using: {
(result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
detector.enumerateMatches(in: text, options: [], range: NSRange(location: 0, length: text.characters.count), using: {(result: NSTextCheckingResult?, _, _) -> Void in
if let result = result, let url = result.url {
urls.append(url)
}
Expand Down Expand Up @@ -357,10 +355,8 @@ extension String {

///EZSE: Returns the first index of the occurency of the character in String
public func getIndexOf(_ char: Character) -> Int? {
for (index, c) in characters.enumerated() {
if c == char {
return index
}
for (index, c) in characters.enumerated() where c == char {
return index
}
return nil
}
Expand Down
26 changes: 13 additions & 13 deletions Sources/UIFontExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public enum FontType: String {

/// EZSwiftExtensions
public enum FontName: String {
case HelveticaNeue = "HelveticaNeue"
case Helvetica = "Helvetica"
case Futura = "Futura"
case Menlo = "Menlo"
case Avenir = "Avenir"
case AvenirNext = "AvenirNext"
case Didot = "Didot"
case AmericanTypewriter = "AmericanTypewriter"
case Baskerville = "Baskerville"
case Geneva = "Geneva"
case GillSans = "GillSans"
case SanFranciscoDisplay = "SanFranciscoDisplay"
case Seravek = "Seravek"
case HelveticaNeue
case Helvetica
case Futura
case Menlo
case Avenir
case AvenirNext
case Didot
case AmericanTypewriter
case Baskerville
case Geneva
case GillSans
case SanFranciscoDisplay
case Seravek
}

extension UIFont {
Expand Down
2 changes: 1 addition & 1 deletion Sources/UISliderExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension UISlider {
public func setValue(_ value: Float, duration: Double) {
UIView.animate(withDuration: duration, animations: { () -> Void in
self.setValue(self.value, animated: true)
}, completion: { (bool) -> Void in
}, completion: { (_) -> Void in
UIView.animate(withDuration: duration, animations: { () -> Void in
self.setValue(value, animated: true)
}, completion: nil)
Expand Down
4 changes: 2 additions & 2 deletions Sources/UITextFieldExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Wang Yu on 6/26/16.
// Copyright © 2016 Goktug Yilmaz. All rights reserved.
//
// swiftlint:disable line_length

#if os(iOS) || os(tvOS)

Expand All @@ -14,7 +15,6 @@ extension UITextField {
/// EZSE: Regular exp for email
static let emailRegex = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"


/// EZSwiftExtensions: Automatically sets these values: backgroundColor = clearColor, textColor = ThemeNicknameColor, clipsToBounds = true,
/// textAlignment = Left, userInteractionEnabled = true, editable = false, scrollEnabled = false, font = ThemeFontName, fontsize = 17
public convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat) {
Expand Down Expand Up @@ -91,4 +91,4 @@ extension UITextField {
return digitsTest.evaluate(with: self.text)
}
}
#endif
#endif
3 changes: 1 addition & 2 deletions Sources/UIViewControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//
// Created by Goktug Yilmaz on 15/07/15.
// Copyright (c) 2015 Goktug Yilmaz. All rights reserved.
// swiftlint:disable trailing_whitespace

#if os(iOS) || os(tvOS)

Expand Down Expand Up @@ -231,7 +230,7 @@ extension UIViewController {
}

/// EZSE: Hide or show navigation bar
public var isNavBarHidden:Bool {
public var isNavBarHidden: Bool {
get {
return (navigationController?.isNavigationBarHidden)!
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ extension UIView {
//EZSE: Reverse pop, good for button animations
public func reversePop() {
setScale(x: 0.9, y: 0.9)
UIView.animate(withDuration: 0.05, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: { [weak self] Void in
UIView.animate(withDuration: 0.05, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: { [weak self] _ in
self?.setScale(x: 1, y: 1)
}) { (bool) in }
}) { (_) in }
}
}

Expand Down
3 changes: 1 addition & 2 deletions Sources/URLExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// Copyright (c) 2016 Goktug Yilmaz. All rights reserved.
//
// swiftlint:disable line_length
// swiftlint:disable trailing_whitespace

#if os(iOS) || os(tvOS)

Expand All @@ -33,7 +32,7 @@ extension URL {
let request = NSMutableURLRequest(url: self, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: timeoutInterval)
request.httpMethod = "HEAD"
request.setValue("", forHTTPHeaderField: "Accept-Encoding")
URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) in
URLSession.shared.dataTask(with: request as URLRequest) { (_, response, _) in
let contentLength: Int64 = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown
DispatchQueue.global(qos: .default).async(execute: {
completionHandler(contentLength)
Expand Down

0 comments on commit 3b7e548

Please sign in to comment.