InMemoryStorage

open class InMemoryStorage<StoredValue> : Storage

Storage that stores values in memory; values will not be persisted between app launches or instances of InMemoryStorage.

  • The type the InMemoryStorage can store.

    Declaration

    Swift

    public typealias Value = StoredValue
  • Create a new empty instance of InMemoryStorage.

    Declaration

    Swift

    public init()
  • Store the provided value against the specified key.

    Declaration

    Swift

    open func storeValue(_ value: StoredValue, key: String)

    Parameters

    value

    The value to store.

    key

    The key to store the value against.

  • Removes the value for the provide key.

    Declaration

    Swift

    open func removeValue(for key: String)

    Parameters

    key

    The key of the value to be removed.

  • Returns the value for the provided key, or nil if the value does not exist.

    Declaration

    Swift

    open func retrieveValue(for key: String) -> StoredValue?

    Parameters

    key

    The key of the value to retrieve.

    Return Value

    The stored value, or nil if the a value does not exist for the specified key.

  • Add a closure that will be called when the specified key is updated.

    Declaration

    Swift

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

    Parameters

    key

    The key to listen for changes to.

    updateListener

    The 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.