Make 'keychain' a static class variable

This commit is contained in:
Danny Moesch 2019-06-24 20:46:17 +02:00 committed by Mingshen Sun
parent e5b31f3d92
commit 5d1a3eae1a

View file

@ -11,31 +11,32 @@ import SwiftyUserDefaults
import KeychainAccess
public class Utils {
private static let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
public static func getPasswordFromKeychain(name: String) -> String? {
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
return try? keychain.getString(name)
}
public static func addPasswordToKeychain(name: String, password: String?) {
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
keychain[name] = password
}
public static func removeKeychain(name: String) {
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
try? keychain.remove(name)
}
public static func removeAllKeychain() {
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
try? keychain.removeAll()
}
public static func copyToPasteboard(textToCopy: String?) {
guard textToCopy != nil else {
return
}
UIPasteboard.general.string = textToCopy
}
public static func attributedPassword(plainPassword: String) -> NSAttributedString{
let attributedPassword = NSMutableAttributedString.init(string: plainPassword)
// draw all digits in the password into red