UsageStoring
public protocol UsageStoring : AnyObject
This protocol provides an API to access data contained in the UsageStoring for a single target identifier.
-
A Read-only property that holds attribution value for a store instance.
Declaration
Swift
var storageID: String { get }
-
A Read-only property that holds store instance initializtion timestamp.
Declaration
Swift
var initTimestamp: Date { get }
-
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
func removeRecords(before date: Date, after end: Date?, targetID: String)
Parameters
date
expiration date
end
range ending date
targetID
target identifier to remove records by
-
Creates a UsageSnapshotting 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
func snapshot(for targetID: String) -> UsageSnapshotting
Parameters
targetID
the target identifier
Return Value
the UsageSnaphotting object containing the UsageRecords
-
Creates a UsageSnapshotting 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
func snapshot(for targetID: String, till date: Date?) -> UsageSnapshotting
Parameters
targetID
the target identifier
date
fetched data till this date
Return Value
the UsageSnaphotting object containing the UsageRecords
-
Stores the given UsageRecord for the given target identifier.
Declaration
Swift
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
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
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
@available(*, deprecated, message: "Use records(filter: UsageRecordFilter?, for snapshot: UsageSnapshotting, _ body: (UsageRecord﹚ -> Bool﹚ instead.") 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
-
Iterates through UsageRecords based on provided filter.
Declaration
Swift
func records(filter: UsageRecordFilter?, for snapshot: UsageSnapshotting, _ body: (UsageRecord) -> Bool)
Parameters
filter
A
UsageRecordFilter
object based on which records are filtered.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
func recordCount(for snapshot: UsageSnapshotting) -> Int
Parameters
snapshot
the UsageSnaphotting object containing the UsageRecords
Return Value
number of records found in the store