Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed self. when not needed #579

Merged
merged 4 commits into from Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/Extensions/AppKit/NSImageExtensions.swift
Expand Up @@ -18,8 +18,8 @@ extension NSImage {
/// - Returns: scaled NSImage
public func scaled(toMaxSize: NSSize) -> NSImage {
var ratio: Float = 0.0
let imageWidth = Float(self.size.width)
let imageHeight = Float(self.size.height)
let imageWidth = Float(size.width)
let imageHeight = Float(size.height)
let maxWidth = Float(toMaxSize.width)
let maxHeight = Float(toMaxSize.height)

Expand All @@ -40,8 +40,8 @@ extension NSImage {
let newSize: NSSize = NSSize(width: Int(newWidth), height: Int(newHeight))

// Cast the NSImage to a CGImage
var imageRect: CGRect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
let imageRef = self.cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
var imageRect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let imageRef = cgImage(forProposedRect: &imageRect, context: nil, hints: nil)

// Create NSImage from the CGImage using the new size
let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/AppKit/NSViewExtensions.swift
Expand Up @@ -132,12 +132,12 @@ extension NSView {
///
/// - Parameter subviews: array of subviews to add to self.
public func addSubviews(_ subviews: [NSView]) {
subviews.forEach({self.addSubview($0)})
subviews.forEach { addSubview($0) }
}

/// SwifterSwift: Remove all subviews in view.
public func removeSubviews() {
subviews.forEach({$0.removeFromSuperview()})
subviews.forEach { $0.removeFromSuperview() }
}

}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Extensions/Foundation/URLExtensions.swift
Expand Up @@ -70,7 +70,7 @@ public extension URL {
///
/// - Parameter key: The key of a query value.
public func queryValue(for key: String) -> String? {
let stringURL = self.absoluteString
let stringURL = absoluteString
guard let items = URLComponents(string: stringURL)?.queryItems else { return nil }
for item in items where item.name == key {
return item.value
Expand Down Expand Up @@ -108,8 +108,8 @@ public extension URL {
/// let url = URL(string: "https://domain.com")!
/// print(url.droppedScheme()) // prints "domain.com"
public func droppedScheme() -> URL? {
if let scheme = self.scheme {
let droppedScheme = String(self.absoluteString.dropFirst(scheme.count + 3))
if let scheme = scheme {
let droppedScheme = String(absoluteString.dropFirst(scheme.count + 3))
return URL(string: droppedScheme)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/Foundation/UserDefaultsExtensions.swift
Expand Up @@ -48,7 +48,7 @@ public extension UserDefaults {
/// - decoder: Custom JSONDecoder instance. Defaults to `JSONDecoder()`.
/// - Returns: Codable object for key (if exists).
public func object<T: Codable>(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? {
guard let data = self.value(forKey: key) as? Data else { return nil }
guard let data = value(forKey: key) as? Data else { return nil }
return try? decoder.decode(type.self, from: data)
}

Expand All @@ -60,7 +60,7 @@ public extension UserDefaults {
/// - encoder: Custom JSONEncoder instance. Defaults to `JSONEncoder()`.
public func set<T: Codable>(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) {
let data = try? encoder.encode(object)
self.set(data, forKey: key)
set(data, forKey: key)
}

}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/Shared/ColorExtensions.swift
Expand Up @@ -231,7 +231,7 @@ public extension Color {
public func lighten(by percentage: CGFloat = 0.2) -> Color {
// https://stackoverflow.com/questions/38435308/swift-get-lighter-and-darker-color-variations-for-a-given-uicolor
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
self.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
return Color(red: min(red + percentage, 1.0),
green: min(green + percentage, 1.0),
blue: min(blue + percentage, 1.0),
Expand All @@ -248,7 +248,7 @@ public extension Color {
public func darken(by percentage: CGFloat = 0.2) -> Color {
// https://stackoverflow.com/questions/38435308/swift-get-lighter-and-darker-color-variations-for-a-given-uicolor
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
self.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
return Color(red: max(red - percentage, 0),
green: max(green - percentage, 0),
blue: max(blue - percentage, 0),
Expand Down
4 changes: 2 additions & 2 deletions Sources/Extensions/SwiftStdlib/IntExtensions.swift
Expand Up @@ -70,7 +70,7 @@ public extension Int {
public var digits: [Int] {
guard self != 0 else { return [0] }
var digits = [Int]()
var number = self.abs
var number = abs

while number != 0 {
let xNumber = number % 10
Expand All @@ -85,7 +85,7 @@ public extension Int {
/// SwifterSwift: Number of digits of integer value.
public var digitsCount: Int {
guard self != 0 else { return 1 }
let number = Double(self.abs)
let number = Double(abs)
return Int(log10(number) + 1)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/SwiftStdlib/OptionalExtensions.swift
Expand Up @@ -57,7 +57,7 @@ public extension Optional {
/// - Parameter block: a block to run if self is not nil.
public func run(_ block: (Wrapped) -> Void) {
// http://www.russbishop.net/improving-optionals
_ = self.map(block)
_ = map(block)
}

/// SwifterSwift: Assign an optional value to a variable only if the value is not nil.
Expand Down
10 changes: 5 additions & 5 deletions Sources/Extensions/SwiftStdlib/StringExtensions.swift
Expand Up @@ -100,7 +100,7 @@ public extension String {
/// "".firstCharacterAsString -> nil
///
public var firstCharacterAsString: String? {
guard let first = self.first else { return nil }
guard let first = first else { return nil }
return String(first)
}

Expand Down Expand Up @@ -259,7 +259,7 @@ public extension String {
/// "".lastCharacterAsString -> nil
///
public var lastCharacterAsString: String? {
guard let last = self.last else { return nil }
guard let last = last else { return nil }
return String(last)
}

Expand Down Expand Up @@ -400,15 +400,15 @@ public extension String {
#if canImport(Foundation)
/// SwifterSwift: Check if the given string contains only white spaces
public var isWhitespace: Bool {
return self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
return trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
}
#endif

#if os(iOS) || os(tvOS)
/// SwifterSwift: Check if the given string spelled correctly
public var isSpelledCorrectly: Bool {
let checker = UITextChecker()
let range = NSRange(location: 0, length: self.utf16.count)
let range = NSRange(location: 0, length: utf16.count)

let misspelledRange = checker.rangeOfMisspelledWord(in: self, range: range, startingAt: 0, wrap: false, language: Locale.preferredLanguages.first ?? "en")
return misspelledRange.location == NSNotFound
Expand Down Expand Up @@ -775,7 +775,7 @@ public extension String {
/// - i: string index the slicing should start from.
/// - length: amount of characters to be sliced after given index.
public mutating func slice(from i: Int, length: Int) {
if let str = self.slicing(from: i, length: length) {
if let str = slicing(from: i, length: length) {
self = String(str)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Extensions/UIKit/UIButtonExtensions.swift
Expand Up @@ -145,21 +145,21 @@ public extension UIButton {
///
/// - Parameter image: UIImage.
public func setImageForAllStates(_ image: UIImage) {
states.forEach { self.setImage(image, for: $0) }
states.forEach { setImage(image, for: $0) }
}

/// SwifterSwift: Set title color for all states.
///
/// - Parameter color: UIColor.
public func setTitleColorForAllStates(_ color: UIColor) {
states.forEach { self.setTitleColor(color, for: $0) }
states.forEach { setTitleColor(color, for: $0) }
}

/// SwifterSwift: Set title for all states.
///
/// - Parameter title: title string.
public func setTitleForAllStates(_ title: String) {
states.forEach { self.setTitle(title, for: $0) }
states.forEach { setTitle(title, for: $0) }
}

/// SwifterSwift: Center align title text and image on UIButton
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/UIKit/UICollectionViewExtensions.swift
Expand Up @@ -33,7 +33,7 @@ public extension UICollectionView {
public func numberOfItems() -> Int {
var section = 0
var itemsCount = 0
while section < self.numberOfSections {
while section < numberOfSections {
itemsCount += numberOfItems(inSection: section)
section += 1
}
Expand Down
Expand Up @@ -14,7 +14,7 @@ public extension UIGestureRecognizer {

/// SwifterSwift: Remove Gesture Recognizer from its view.
public func removeFromView() {
self.view?.removeGestureRecognizer(self)
view?.removeGestureRecognizer(self)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/UIKit/UIImageExtensions.swift
Expand Up @@ -173,7 +173,7 @@ public extension UIImage {
context.setBlendMode(CGBlendMode.normal)

let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
guard let mask = self.cgImage else { return self }
guard let mask = cgImage else { return self }
context.clip(to: rect, mask: mask)
context.fill(rect)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/UIKit/UITableViewExtensions.swift
Expand Up @@ -177,7 +177,7 @@ public extension UITableView {
/// - Parameter indexPath: An IndexPath to check
/// - Returns: Boolean value for valid or invalid IndexPath
public func isValidIndexPath(_ indexPath: IndexPath) -> Bool {
return indexPath.section < self.numberOfSections && indexPath.row < self.numberOfRows(inSection: indexPath.section)
return indexPath.section < numberOfSections && indexPath.row < numberOfRows(inSection: indexPath.section)
}

/// SwifterSwift: Safely scroll to possibly invalid IndexPath
Expand Down
8 changes: 4 additions & 4 deletions Sources/Extensions/UIKit/UITextFieldExtensions.swift
Expand Up @@ -132,7 +132,7 @@ public extension UITextField {
/// - Parameter color: placeholder text color.
public func setPlaceHolderTextColor(_ color: UIColor) {
guard let holder = placeholder, !holder.isEmpty else { return }
self.attributedPlaceholder = NSAttributedString(string: holder, attributes: [.foregroundColor: color])
attributedPlaceholder = NSAttributedString(string: holder, attributes: [.foregroundColor: color])
}

/// SwifterSwift: Add padding to the left of the textfield rect.
Expand All @@ -152,9 +152,9 @@ public extension UITextField {
public func addPaddingLeftIcon(_ image: UIImage, padding: CGFloat) {
let imageView = UIImageView(image: image)
imageView.contentMode = .center
self.leftView = imageView
self.leftView?.frame.size = CGSize(width: image.size.width + padding, height: image.size.height)
self.leftViewMode = UITextField.ViewMode.always
leftView = imageView
leftView?.frame.size = CGSize(width: image.size.width + padding, height: image.size.height)
leftViewMode = .always
}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/UIKit/UIViewControllerExtensions.swift
Expand Up @@ -15,7 +15,7 @@ public extension UIViewController {
/// SwifterSwift: Check if ViewController is onscreen and not hidden.
public var isVisible: Bool {
// http://stackoverflow.com/questions/2777438/how-to-tell-if-uiviewcontrollers-view-is-visible
return self.isViewLoaded && view.window != nil
return isViewLoaded && view.window != nil
}

}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions/UIKit/UIViewExtensions.swift
Expand Up @@ -280,7 +280,7 @@ public extension UIView {
///
/// - Parameter subviews: array of subviews to add to self.
public func addSubviews(_ subviews: [UIView]) {
subviews.forEach({ self.addSubview($0) })
subviews.forEach { addSubview($0) }
}

/// SwifterSwift: Fade in view.
Expand Down