UsageStore

public class UsageStore : UsageStoring

The store implementation to store and read usage records.

  • StorageID name used for shared data.

    Declaration

    Swift

    public static let unattributedStorageID: String
  • The default folder url used for the UsageStore.

    Declaration

    Swift

    public static let defaultFolderURL: URL
  • A Read-only property that holds attribution value for UsageStore set during initialization.

    Declaration

    Swift

    private(set) public var storageID: String { get }
  • A Read-only property that holds UsageStore initializtion timestamp.

    Declaration

    Swift

    private(set) public var initTimestamp: Date { get }
  • The given path should be a folder path where the store will be created.

    • path: store folder path
    • storageID: optional attributed basename of store
    • encryptionKey: optional value (MUST remain constant after initialization)

    Declaration

    Swift

    public init(with path: URL = defaultFolderURL, storageID: UUID? = nil, encryptionKey: String? = nil) throws
  • Delete all records with the provided target identifier from the storage before the provided date (or specifying optional parameter provides a range of dates - between before and after inclusively). Can be used to remove ‘expired’ data. ///

    Declaration

    Swift

    public func removeRecords(before date: Date = Date(), after end: Date? = nil, targetID: String)

    Parameters

    before

    expiration date

    after

    range ending date

    targetID

    target identifier to remove records by

  • Creates a UsageSnapshot object for the given target identifier. A snapshot object is the store representation narrowed down to a specific target identifier containing the data exists in the store at the creation time of the snapshot object.

    Declaration

    Swift

    public func snapshot(for targetID: String) -> UsageSnapshotting

    Parameters

    targetID

    the target identifier

    Return Value

    UsageSnapshot instance

  • Creates a UsageSnapshot object for the given target identifier. A snapshot object is the store representation narrowed down to a specific target identifier containing the data stored till the given time in the store.

    Declaration

    Swift

    public func snapshot(for targetID: String, till date: Date?) -> UsageSnapshotting

    Parameters

    date

    all records till this date

    targetID

    the target identifier

    Return Value

    UsageSnapshot instance

  • Iterates through UsageRecords based on provided filter. Additionally, these records are organized in descending order by UsageRecord.date.

    Declaration

    Swift

    public func records(filter: UsageRecordFilter, _ body: (UsageRecord) -> Bool)

    Parameters

    filter

    A UsageRecordFilter object based on which records are filtered.

    body

    the iterating block - return false if you want to terminate the iteration, true otherwise

  • Stores the given UsageRecord for the given target identifier.

    Declaration

    Swift

    public func store(record: UsageRecord, for targetID: String)

    Parameters

    record

    the UsageRecord to be saved

    targetID

    the target identifier

  • Collects all the distinct target identifiers.

    Declaration

    Swift

    public func targetIdentifiers() -> [String]

    Return Value

    the target identifiers present in the store

  • Delete all records based on the records found in the provided UsageSnapshotting object.

    Declaration

    Swift

    public func removeRecords(using snapshot: UsageSnapshotting)

    Parameters

    snapshot

    the UsageSnaphotting object containing the UsageRecords

  • Iterates through the UsageRecords which belong to the given UsageSnapshotting object.

    Declaration

    Swift

    public func records(for snapshot: UsageSnapshotting, _ body: (UsageRecord) -> Bool)

    Parameters

    snapshot

    the UsageSnaphotting object containing the UsageRecords

    body

    the iterating block - return false if you want to terminate the iteration, true otherwise

  • Returns the number of UsageRecords present in the store based on the provided UsageSnapshotting instance. Only the records present in the UsageSnapshotting (for a given target identifier) are counted.

    Declaration

    Swift

    public func recordCount(for snapshot: UsageSnapshotting) -> Int

    Parameters

    snapshot

    the UsageSnaphotting object containing the UsageRecords

    Return Value

    number of records found in the store