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
UsageStoreset during initialization.Declaration
Swift
private(set) public var storageID: String { get } -
A Read-only property that holds
UsageStoreinitializtion 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
beforeexpiration date
afterrange ending date
targetIDtarget 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) -> UsageSnapshottingParameters
targetIDthe 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?) -> UsageSnapshottingParameters
dateall records till this date
targetIDthe target identifier
Return Value
UsageSnapshot instance
-
Stores the given UsageRecord for the given target identifier.
Declaration
Swift
public func store(record: UsageRecord, for targetID: String)Parameters
recordthe UsageRecord to be saved
targetIDthe 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
snapshotthe UsageSnaphotting object containing the UsageRecords
-
Iterates through UsageRecords based on provided filter.
Declaration
Swift
public func records(filter: UsageRecordFilter?, for snapshot: UsageSnapshotting, _ body: (UsageRecord) -> Bool)Parameters
filterA
UsageRecordFilterobject based on which records are filtered.snapshotUsageSnaphotting object containing the UsageRecords
bodythe iterating block - return
falseif you want to terminate the iteration,trueotherwise -
Iterates through the UsageRecords which belong to the given UsageSnapshotting object.
Declaration
Swift
@available(*, deprecated, message: "Use records(filter: UsageRecordFilter?, for snapshot: UsageSnapshotting, _ body: (UsageRecord﹚ -> Bool﹚ instead.") public func records(for snapshot: UsageSnapshotting, _ body: (UsageRecord) -> Bool)Parameters
snapshotthe UsageSnaphotting object containing the UsageRecords
bodythe 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) -> IntParameters
snapshotthe UsageSnaphotting object containing the UsageRecords
Return Value
number of records found in the store