SingleKeychainStore
open class SingleKeychainStore<T> where T : Decodable, T : Encodable
SingleKeychainStore
offers a convenient way to store a single Codable
object securely in the OS Keychain.
Warning: Keep in mind that values stored in in the OS keychain is not removed when the app is deleted.
-
serviceName is used for the kSecAttrService property to uniquely identify this keychain accessor.
Declaration
Swift
public let serviceName: String
-
Store’s unique identifier.
Warning: Never use the same identifier for two -or more- different stores.
Declaration
Swift
public let uniqueIdentifier: String
-
JSON encoder. default is JSONEncoder()
Declaration
Swift
open var encoder: JSONEncoder
-
JSON decoder. default is JSONDecoder()
Declaration
Swift
open var decoder: JSONDecoder
-
Initialize store.
Warning: Never use the same identifier for two -or more- different stores.
Declaration
Swift
required public init(serviceName: String = Bundle.main.bundleIdentifier ?? "PersistenceKit", uniqueIdentifier: String)
Parameters
serviceName
service name. default is bundle identifier or
PersistenceKit
uniqueIdentifier
uniqueIdentifier: store’s unique identifier.
-
Save object to store.
Throws
JSON encoding error.Declaration
Swift
open func save(_ object: T, withAccessibilityOption option: KeychainAccessibilityOption = .whenUnlocked) throws
Parameters
object
object to save.
option
KeychainAccessibilityOption
. default is .whenUnlocked -
Update object in store.
Throws
JSON encoding error.Declaration
Swift
open func update(_ object: T, withAccessibilityOption option: KeychainAccessibilityOption = .whenUnlocked) throws
Parameters
object
object to save.
option
KeychainAccessibilityOption
. default is KeychainAccessibilityOption.whenUnlocked -
Get object from store.
Declaration
Swift
open func object(accessibilityOption option: KeychainAccessibilityOption = .whenUnlocked) -> T?
Parameters
option
KeychainAccessibilityOption
. default is KeychainAccessibilityOption.whenUnlockedReturn Value
optional object.
-
Delete object from store.
Declaration
Swift
open func delete(accessibilityOption option: KeychainAccessibilityOption = .whenUnlocked)
Parameters
option
KeychainAccessibilityOption. default is KeychainAccessibilityOption.whenUnlocked