Format code with SwiftFormat automatically in every build
This commit is contained in:
parent
f167ab7549
commit
7f9f0e43b2
100 changed files with 1124 additions and 1063 deletions
|
|
@ -7,7 +7,6 @@
|
|||
//
|
||||
|
||||
extension Array {
|
||||
|
||||
func slices(count: UInt) -> [ArraySlice<Element>] {
|
||||
guard count != 0 else {
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -8,18 +8,18 @@
|
|||
|
||||
extension String {
|
||||
public func localize() -> String {
|
||||
return NSLocalizedString(self, value: "#\(self)#", comment: "")
|
||||
NSLocalizedString(self, value: "#\(self)#", comment: "")
|
||||
}
|
||||
|
||||
public func localize(_ firstValue: CVarArg) -> String {
|
||||
return String(format: localize(), firstValue)
|
||||
String(format: localize(), firstValue)
|
||||
}
|
||||
|
||||
public func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
|
||||
return String(format: localize(), firstValue, secondValue)
|
||||
String(format: localize(), firstValue, secondValue)
|
||||
}
|
||||
|
||||
public func localize(_ error: Error) -> String {
|
||||
return localize(error.localizedDescription)
|
||||
localize(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
extension String {
|
||||
public var trimmed: String {
|
||||
return trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
public func stringByAddingPercentEncodingForRFC3986() -> String? {
|
||||
|
|
@ -19,12 +19,12 @@ extension String {
|
|||
}
|
||||
|
||||
public func splitByNewline() -> [String] {
|
||||
return split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
|
||||
split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public static func | (left: String, right: String) -> String {
|
||||
return right.isEmpty ? left : left + "\n" + right
|
||||
right.isEmpty ? left : left + "\n" + right
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
// Copyright © 2020 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
extension UIAlertAction {
|
||||
public static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
return cancel() { _ in
|
||||
cancel { _ in
|
||||
controller.navigationController?.popViewController(animated: true)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ extension UIAlertAction {
|
|||
cancel(with: "Dismiss", handler: handler)
|
||||
}
|
||||
|
||||
public static func cancel(with title: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
public static func cancel(with _: String, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
UIAlertAction(title: "Cancel".localize(), style: .cancel, handler: handler)
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ extension UIAlertAction {
|
|||
}
|
||||
|
||||
public static func okAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
return ok() { _ in
|
||||
ok { _ in
|
||||
controller.navigationController?.popViewController(animated: true)
|
||||
}
|
||||
}
|
||||
|
|
@ -41,13 +41,12 @@ extension UIAlertAction {
|
|||
public static func selectKey(controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
|
||||
UIAlertAction(title: "Select Key", style: .default) { _ in
|
||||
let selectKeyAlert = UIAlertController(title: "Select from imported keys", message: nil, preferredStyle: .actionSheet)
|
||||
try? PGPAgent.shared.getShortKeyID().forEach({ k in
|
||||
try? PGPAgent.shared.getShortKeyID().forEach { k in
|
||||
let action = UIAlertAction(title: k, style: .default, handler: handler)
|
||||
selectKeyAlert.addAction(action)
|
||||
})
|
||||
}
|
||||
selectKeyAlert.addAction(UIAlertAction.cancelAndPopView(controller: controller))
|
||||
controller.present(selectKeyAlert, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@ private var kAssociationKeyNextField: UInt8 = 0
|
|||
extension UITextField {
|
||||
@IBOutlet var nextField: UITextField? {
|
||||
get {
|
||||
return objc_getAssociatedObject(self, &kAssociationKeyNextField) as? UITextField
|
||||
objc_getAssociatedObject(self, &kAssociationKeyNextField) as? UITextField
|
||||
}
|
||||
set(newField) {
|
||||
objc_setAssociatedObject(self, &kAssociationKeyNextField, newField, .OBJC_ASSOCIATION_RETAIN)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func shake() {
|
||||
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
|
||||
animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
|
||||
animation.repeatCount = 3
|
||||
animation.duration = 0.2/TimeInterval(animation.repeatCount)
|
||||
animation.duration = 0.2 / TimeInterval(animation.repeatCount)
|
||||
animation.autoreverses = true
|
||||
animation.values = [3, -3]
|
||||
layer.add(animation, forKey: "shake")
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
//
|
||||
|
||||
extension UIViewController {
|
||||
@objc public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
@objc
|
||||
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
if textField.nextField != nil {
|
||||
textField.nextField?.becomeFirstResponder()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,29 +9,28 @@
|
|||
import Foundation
|
||||
|
||||
extension UIView {
|
||||
|
||||
// Save anchors: https://stackoverflow.com/questions/46317061/use-safe-area-layout-programmatically
|
||||
var safeTopAnchor: NSLayoutYAxisAnchor {
|
||||
if #available(iOS 11.0, *) {
|
||||
return self.safeAreaLayoutGuide.topAnchor
|
||||
} else {
|
||||
return self.topAnchor
|
||||
return topAnchor
|
||||
}
|
||||
}
|
||||
|
||||
var safeLeftAnchor: NSLayoutXAxisAnchor {
|
||||
if #available(iOS 11.0, *){
|
||||
if #available(iOS 11.0, *) {
|
||||
return self.safeAreaLayoutGuide.leftAnchor
|
||||
} else {
|
||||
return self.leftAnchor
|
||||
return leftAnchor
|
||||
}
|
||||
}
|
||||
|
||||
var safeRightAnchor: NSLayoutXAxisAnchor {
|
||||
if #available(iOS 11.0, *){
|
||||
if #available(iOS 11.0, *) {
|
||||
return self.safeAreaLayoutGuide.rightAnchor
|
||||
} else {
|
||||
return self.rightAnchor
|
||||
return rightAnchor
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ extension UIView {
|
|||
if #available(iOS 11.0, *) {
|
||||
return self.safeAreaLayoutGuide.bottomAnchor
|
||||
} else {
|
||||
return self.bottomAnchor
|
||||
return bottomAnchor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue