Format code with SwiftFormat automatically in every build

This commit is contained in:
Danny Moesch 2020-06-28 21:25:40 +02:00 committed by Mingshen Sun
parent f167ab7549
commit 7f9f0e43b2
100 changed files with 1124 additions and 1063 deletions

View file

@ -9,9 +9,8 @@
import KeychainAccess
public class AppKeychain: KeyStore {
public static let shared = AppKeychain()
private let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
.accessibility(.whenUnlockedThisDeviceOnly)
.synchronizable(false)
@ -25,15 +24,15 @@ public class AppKeychain: KeyStore {
}
public func contains(key: String) -> Bool {
return (try? keychain.contains(key)) ?? false
(try? keychain.contains(key)) ?? false
}
public func get(for key: String) -> Data? {
return try? keychain.getData(key)
try? keychain.getData(key)
}
public func get(for key: String) -> String? {
return try? keychain.getString(key)
try? keychain.getString(key)
}
public func removeContent(for key: String) {

View file

@ -10,7 +10,6 @@ import Foundation
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
public extension FileManager {
/// This method calculates the accumulated size of a directory on the volume in bytes.
///
/// As there's no simple way to get this information from the file system it has to crawl the entire hierarchy,
@ -19,8 +18,7 @@ public extension FileManager {
///
/// - note: There are a couple of oddities that are not taken into account (like symbolic links, meta data of
/// directories, hard links, ...).
func allocatedSizeOfDirectoryAtURL(directoryURL : URL) throws -> UInt64 {
func allocatedSizeOfDirectoryAtURL(directoryURL: URL) throws -> UInt64 {
// We'll sum up content size here:
var accumulatedSize = UInt64(0)
@ -29,7 +27,7 @@ public extension FileManager {
URLResourceKey.isRegularFileKey,
URLResourceKey.fileAllocatedSizeKey,
URLResourceKey.totalFileAllocatedSizeKey,
]
]
// The error handler simply signals errors to outside code.
var errorDidOccur: Error?
@ -38,7 +36,6 @@ public extension FileManager {
return false
}
// We have to enumerate all directory contents, including subdirectories.
let enumerator = self.enumerator(at: directoryURL,
includingPropertiesForKeys: prefetchedProperties,
@ -91,4 +88,3 @@ public extension FileManager {
return accumulatedSize
}
}

View file

@ -32,7 +32,7 @@ public final class Globals {
public static let gitPassword = "gitPassword"
public static let gitSSHPrivateKeyPassphrase = "gitSSHPrivateKeyPassphrase"
public static let pgpKeyPassphrase = "pgpKeyPassphrase"
public static let gitSignatureDefaultName = "Pass for iOS"
public static let gitSignatureDefaultEmail = "user@passforios"
@ -43,14 +43,15 @@ public final class Globals {
// UI related
public static let tableCellButtonSize = CGFloat(20.0)
private init() { }
private init() {}
}
public extension Bundle {
var releaseVersionNumber: String? {
return infoDictionary?["CFBundleShortVersionString"] as? String
infoDictionary?["CFBundleShortVersionString"] as? String
}
var buildVersionNumber: String? {
return infoDictionary?["CFBundleVersion"] as? String
infoDictionary?["CFBundleVersion"] as? String
}
}

View file

@ -45,6 +45,6 @@ public class KeyFileManager {
}
public func doesKeyFileExist() -> Bool {
return FileManager.default.fileExists(atPath: keyPath)
FileManager.default.fileExists(atPath: keyPath)
}
}

View file

@ -7,7 +7,6 @@
//
public class Utils {
public static func copyToPasteboard(textToCopy: String?) {
guard textToCopy != nil else {
return
@ -15,8 +14,8 @@ public class Utils {
UIPasteboard.general.string = textToCopy
}
public static func attributedPassword(plainPassword: String) -> NSAttributedString{
let attributedPassword = NSMutableAttributedString.init(string: plainPassword)
public static func attributedPassword(plainPassword: String) -> NSAttributedString {
let attributedPassword = NSMutableAttributedString(string: plainPassword)
// draw all digits in the password into red
// draw all punctuation characters in the password into blue
for (index, element) in plainPassword.unicodeScalars.enumerated() {
@ -40,24 +39,24 @@ public class Utils {
}
public static func createRequestPGPKeyPassphraseHandler(controller: UIViewController) -> (String) -> String {
return { keyID in
{ keyID in
let sem = DispatchSemaphore(value: 0)
var passphrase = ""
DispatchQueue.main.async {
let title = "Passphrase".localize() + " (\(keyID.suffix(8)))"
let message = "FillInPgpPassphrase.".localize()
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction.ok() { _ in
alert.addAction(UIAlertAction.ok { _ in
passphrase = alert.textFields?.first?.text ?? ""
sem.signal()
})
alert.addTextField() { textField in
alert.addTextField { textField in
textField.text = AppKeychain.shared.get(for: AppKeychain.getPGPKeyPassphraseKey(keyID: keyID)) ?? ""
textField.isSecureTextEntry = true
}
controller.present(alert, animated: true)
}
let _ = sem.wait(timeout: DispatchTime.distantFuture)
_ = sem.wait(timeout: DispatchTime.distantFuture)
if Defaults.isRememberPGPPassphraseOn {
AppKeychain.shared.add(string: passphrase, for: AppKeychain.getPGPKeyPassphraseKey(keyID: keyID))
}
@ -65,4 +64,3 @@ public class Utils {
}
}
}