DataStore
public protocol DataStore : AnyObject, DataItemExtractor
Generic data storage for storing DataInput and retrieving DataItem objects.
Implementations are not guaranteed to be persistent. For instance, in cases where there may be insufficient storage space on the device, or other reasons such as write permissions etc.
Stored data requires an Expiry to be provided when storing, and expired data will not be
included in any retrieval operations; that is, expired data won’t be returned by get or getAll
but it will also not be included in any aggregate methods such as keys or count.
-
Returns a
DataStoreEditorable to mutate the data in this storage.Declaration
Swift
func edit() -> DataStoreEditorReturn Value
DataStoreEditorto update the stored data. -
Gets a dictionary containing all data stored.
Declaration
Swift
func getAll() -> DataObjectReturn Value
A
DataObjectdictionary with all the data contained in the storage. -
Returns all keys stored in this DataStore
Declaration
Swift
func keys() -> [String]Return Value
A list of all string keys present in the DataStore
-
Returns the number of entries in this DataStore
Declaration
Swift
func count() -> IntReturn Value
the count of all key-value pairs in the DataStore
-
Observable of key-value pairs from this DataStore that have been updated
Declaration
Swift
var onDataUpdated: Observable<DataObject> { get } -
Observable of keys from this DataStore that have been removed or expired
Note that expiration may not happen immediately when the value is expired but may happen asynchronously on a later check
Declaration
Swift
var onDataRemoved: Observable<[String]> { get } -
buildPath(_:Extension methodandSet: expiry: ) Builds a nested path in the data store and sets a value at that location.
This method creates the necessary nested structure (objects and arrays) to accommodate the specified path, then sets the provided item at that location with the given expiry. If any part of the path doesn’t exist, it will be automatically created.
For nested objects, missing dictionary keys will be created as empty dictionaries. For nested arrays, if an index is beyond the current array bounds, the array will be extended with
nilvalues until it reaches the required capacity.Example:
// Creates nested structure: { "user": { "profile": { "name": "John" } } } let path = JSONPath["user"]["profile"]["name"] let nameItem = DataItem(value: "John") try dataStore.buildPath(path, andSet: nameItem, expiry: .session)Throws
An error if the commit operation fails during the transaction.
Declaration
Swift
func buildPath(_ path: JSONObjectPath, andSet item: DataItem, expiry: Expiry) throwsParameters
pathThe
JSONObjectPathspecifying where to set the value. Can include nested object keys and array indices.itemThe
DataItemto store at the specified path location.expiryThe time frame for this data to remain stored before expiring.
View on GitHub