Use SwiftFormat version 0.47.x

This commit is contained in:
Danny Moesch 2020-11-07 12:06:28 +01:00 committed by Mingshen Sun
parent e8389eb262
commit 49c6b25611
18 changed files with 69 additions and 49 deletions

View file

@ -6,21 +6,21 @@
// Copyright © 2019 Bob Sun. All rights reserved.
//
extension String {
public func localize() -> String {
public extension String {
func localize() -> String {
// swiftlint:disable:next nslocalizedstring_key
NSLocalizedString(self, bundle: Bundle.main, value: "#\(self)#", comment: "")
}
public func localize(_ firstValue: CVarArg) -> String {
func localize(_ firstValue: CVarArg) -> String {
String(format: localize(), firstValue)
}
public func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
String(format: localize(), firstValue, secondValue)
}
public func localize(_ error: Error) -> String {
func localize(_ error: Error) -> String {
localize(error.localizedDescription)
}
}

View file

@ -6,25 +6,25 @@
// Copyright © 2018 Bob Sun. All rights reserved.
//
extension String {
public var trimmed: String {
public extension String {
var trimmed: String {
trimmingCharacters(in: .whitespacesAndNewlines)
}
public func stringByAddingPercentEncodingForRFC3986() -> String? {
func stringByAddingPercentEncodingForRFC3986() -> String? {
let unreserved = "-._~/?"
var allowed = CharacterSet.alphanumerics
allowed.insert(charactersIn: unreserved)
return addingPercentEncoding(withAllowedCharacters: allowed)
}
public func splitByNewline() -> [String] {
func splitByNewline() -> [String] {
split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
}
}
extension String {
public static func | (left: String, right: String) -> String {
public extension String {
static func | (left: String, right: String) -> String {
right.isEmpty ? left : left + "\n" + right
}
}

View file

@ -9,32 +9,32 @@
import Foundation
import UIKit
extension UIAlertAction {
public static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
public extension UIAlertAction {
static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
cancel { _ in
controller.navigationController?.popViewController(animated: true)
}
}
public static func cancel(title: String = "Cancel".localize(), handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
static func cancel(title: String = "Cancel".localize(), handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
UIAlertAction(title: title, style: .cancel, handler: handler)
}
public static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
cancel(title: "Dismiss".localize(), handler: handler)
}
public static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
UIAlertAction(title: "Ok".localize(), style: .default, handler: handler)
}
public static func okAndPopView(controller: UIViewController) -> UIAlertAction {
static func okAndPopView(controller: UIViewController) -> UIAlertAction {
ok { _ in
controller.navigationController?.popViewController(animated: true)
}
}
public static func selectKey(controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
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 { keyID in

View file

@ -6,9 +6,9 @@
// Copyright © 2017 Yishi Lin. All rights reserved.
//
extension UIViewController {
public extension UIViewController {
@objc
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField.nextField != nil {
textField.nextField?.becomeFirstResponder()
} else {