Storage

public protocol Storage : AnyObject

A protocol that defines the interface to store, remove, and retrieve values by a string key.

  • Key

    The type of the keys used to reference values in the storage.

    Declaration

    Swift

    associatedtype Key
  • The type of values that can be stored.

    Declaration

    Swift

    associatedtype Value
  • A closure that will be called when an update occurs.

    Declaration

    Swift

    typealias UpdateListener = (Value?) -> Void
  • Store the provided value against the provided key.

    Declaration

    Swift

    func storeValue(_ value: Value, key: Key) throws

    Parameters

    value

    The value to store.

    key

    The key to store the value against.

  • Remove the value for the provided key.

    Declaration

    Swift

    func removeValue(for key: Key) throws

    Parameters

    key

    The key of the value to remove.

  • Retrieve the value for the provided key.

    Throws

    PersistenceError.unexpectedValueType if stored value that is not of type Value.

    Declaration

    Swift

    func retrieveValue(for key: Key) throws -> Value?

    Parameters

    key

    The key of the value to retrieve.

    Return Value

    The stored value, or nil if no value is associated with the key.

  • Add a closure that will be called when a value is updated.

    Declaration

    Swift

    func addUpdateListener(forKey key: Key, updateListener: @escaping UpdateListener) -> AnyCancellable

    Parameters

    key

    The key to subscribe to changes to.

    updateListener

    A closure to call when an update occurs.

    Return Value

    An object that represents the closure’s subscription to changes. This object must be retained by the caller.