StorageDelegate
open class StorageDelegate<T> : Storage, @unchecked Sendable where T : Decodable, T : Encodable, T : Sendable
A storage delegate class that delegates its operations to a storage.
It can optionally cache the stored item in memory.
This class is designed to be subclassed by specific storage strategies (e.g., keychain, in-memory) that conform to the Storage protocol.
Parameters
T
|
The type of the object being stored. Must conform to |
-
Initializer for StorageDelegate
Declaration
Swift
public init(delegate: any Storage<T>, cacheable: Bool = false)Parameters
delegateThe storage to delegate the operations to.
cacheableWhether the storage delegate should cache the object in memory.
-
save(item:Asynchronous) Saves the given item in the storage and optionally in memory.
Declaration
Swift
public func save(item: T) async throwsParameters
itemThe item to save.
-
get()AsynchronousRetrieves the item from memory if it’s cached, otherwise from the storage.
Declaration
Swift
public func get() async throws -> T?Return Value
The item if it exists,
nilotherwise. -
delete()AsynchronousDeletes the item from the storage and removes it from memory if it’s cached.
Declaration
Swift
public func delete() async throws