Keychain
public class Keychain
The Keychain class makes it easy to work with items in the keychain storage.
-
Sets the value of the key. Before setting, the old value is removed. So if you want to delete the key, just set its value to
nil.Throws
The
KeychainErrorif something went wrong.Declaration
Swift
public static func setValue(_ value: Any?, forKey key: String) throwsParameters
valueThe value for the key. Value’s type must conform
NSCodingprotocol. It is implemented by all of the Foundation and most of the UIKit types.keyThe key for which to create a record in the keychain.
-
Returns the value of the key or
nil, if the key does not exist.Throws
The
KeychainErrorif something went wrong.Declaration
Swift
public static func getValue(forKey key: String) throws -> Any?Parameters
keyThe key for which to get the value.
Return Value
The key value.
-
Saves the
SecKeyobject to the keychain. Before saving, the old value is deleted, So, if you want to delete the item, just set its value tonil.Throws
The
KeychainErrorif something’s wrong.Declaration
Swift
public static func setSecKey(_ secKey: SecKey?, forKey key: String) throwsParameters
secKeyThe
SecKeyobject that will be saved.keyThe key name for the
SecKeyitem. -
Returns the
SecKeyobject associated with the key ornil, if the key does not exist.Throws
The
KeychainErrorif something’s wrong.Declaration
Swift
public static func getSecKey(forKey key: String) throws -> SecKey?Parameters
keyThe key for which to get the
SecKey.Return Value
The
SecKeyobject.
View on GitHub
Keychain Class Reference