Make 'keychain' a static class variable
This commit is contained in:
parent
e5b31f3d92
commit
5d1a3eae1a
1 changed files with 5 additions and 4 deletions
|
|
@ -11,31 +11,32 @@ import SwiftyUserDefaults
|
||||||
import KeychainAccess
|
import KeychainAccess
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
|
private static let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||||
|
|
||||||
public static func getPasswordFromKeychain(name: String) -> String? {
|
public static func getPasswordFromKeychain(name: String) -> String? {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
|
||||||
return try? keychain.getString(name)
|
return try? keychain.getString(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func addPasswordToKeychain(name: String, password: String?) {
|
public static func addPasswordToKeychain(name: String, password: String?) {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
|
||||||
keychain[name] = password
|
keychain[name] = password
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func removeKeychain(name: String) {
|
public static func removeKeychain(name: String) {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
|
||||||
try? keychain.remove(name)
|
try? keychain.remove(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func removeAllKeychain() {
|
public static func removeAllKeychain() {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
|
||||||
try? keychain.removeAll()
|
try? keychain.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func copyToPasteboard(textToCopy: String?) {
|
public static func copyToPasteboard(textToCopy: String?) {
|
||||||
guard textToCopy != nil else {
|
guard textToCopy != nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
UIPasteboard.general.string = textToCopy
|
UIPasteboard.general.string = textToCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func attributedPassword(plainPassword: String) -> NSAttributedString{
|
public static func attributedPassword(plainPassword: String) -> NSAttributedString{
|
||||||
let attributedPassword = NSMutableAttributedString.init(string: plainPassword)
|
let attributedPassword = NSMutableAttributedString.init(string: plainPassword)
|
||||||
// draw all digits in the password into red
|
// draw all digits in the password into red
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue