IndexedDataStore

public final class IndexedDataStore

Persistent data store with data objects indexed by identifier.

Creating the Data Store

  • The name of the data store.

    Declaration

    Swift

    public let name: String
  • Creates a data store with the given name.

    Declaration

    Swift

    public init(name: String) throws

    Parameters

    name

    The name of the data store.

Loading Data

  • Value type of the identifier.

    Declaration

    Swift

    public typealias Identifier = String
  • Loads data asynchonously from the persistent data store.

    Declaration

    Swift

    public func loadData<T>(forIdentifier identifier: Identifier, dataTransformer: @escaping (Data) -> T?, completionHandler: @escaping (T?) -> Void)

    Parameters

    identifier

    The identifier of the data.

    dataTransformer

    Transforms data to a specified type.

    completionHandler

    The block to execute after the operation’s main task is completed.

Storing Data

  • Store data asynchronously in persistent data store.

    Declaration

    Swift

    public func storeData(_ dataProvider: @escaping () -> Data?, identifier: Identifier = UUID().uuidString, completionHandler: @escaping (Result<Identifier, Error>) -> Void)

    Parameters

    dataProvider

    The block providing data. Runs on a background thread.

    identifier

    The identifier of the data.

    completionHandler

    The block to execute after the operation’s main task is completed.

Removing Data

  • Removes data stored in the persistent data store.

    Declaration

    Swift

    public func removeData(forIdentifier identifier: Identifier)

    Parameters

    identifier

    The identifier of the data.

  • Removes all the stored data objects.

    Declaration

    Swift

    public func removeAll()

Loading Images

  • Loads image asynchonously from persistent data store.

    Declaration

    Swift

    func loadImage(forIdentifier identifier: Identifier, completionHandler: @escaping (UIImage?) -> Void)

    Parameters

    identifier

    The identifier of the image.

    completionHandler

    The block to execute after the operation’s main task is completed.

Storing Images

  • Store data asynchronously in persistent data store.

    Declaration

    Swift

    func storeImage(_ image: UIImage, identifier: Identifier = UUID().uuidString, completionHandler: @escaping (Result<Identifier, Error>) -> Void)

    Parameters

    image

    UIImage to store.

    identifier

    The identifier of the image.

    completionHandler

    The block to execute after the operation’s main task is completed.