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
KeychainError
if something went wrong.Declaration
Swift
public static func setValue(_ value: Any?, forKey key: String) throws
Parameters
value
The value for the key. Value’s type must conform
NSCoding
protocol. It is implemented by all of the Foundation and most of the UIKit types.key
The 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
KeychainError
if something went wrong.Declaration
Swift
public static func getValue(forKey key: String) throws -> Any?
Parameters
key
The key for which to get the value.
Return Value
The key value.
-
Saves the
SecKey
object 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
KeychainError
if something’s wrong.Declaration
Swift
public static func setSecKey(_ secKey: SecKey?, forKey key: String) throws
Parameters
secKey
The
SecKey
object that will be saved.key
The key name for the
SecKey
item. -
Returns the
SecKey
object associated with the key ornil
, if the key does not exist.Throws
The
KeychainError
if something’s wrong.Declaration
Swift
public static func getSecKey(forKey key: String) throws -> SecKey?
Parameters
key
The key for which to get the
SecKey
.Return Value
The
SecKey
object.