SingleFileStore
open class SingleFileStore<T> where T : Decodable, T : Encodable
SingleFileStore offers a convenient way to store a single Codable objects in the files system.
-
Store’s unique identifier.
Warning: Never use the same identifier for two -or more- different stores.
Declaration
Swift
public let uniqueIdentifier: String -
Store
Expirationoption. default is .neverDeclaration
Swift
public let expiration: Expiration -
JSON encoder. default is JSONEncoder()
Declaration
Swift
open var encoder: JSONEncoder -
JSON decoder. default is JSONDecoder()
Declaration
Swift
open var decoder: JSONDecoder -
Initialize store with given identifier.
Warning: Never use the same identifier for two -or more- different stores.
Declaration
Swift
required public init(uniqueIdentifier: String, expiration: Expiration = .never)Parameters
uniqueIdentifierstore’s unique identifier.
expiryDurationoptional store’s expiry duration default is .never.
-
Save object to store.
Throws
FileManageror JSON encoding error.Declaration
Swift
public func save(_ object: T) throwsParameters
objectobject to save.
-
Save optional object (if not nil) to store.
Throws
FileManageror JSON encoding error.Declaration
Swift
public func save(_ optionalObject: T?) throwsParameters
optionalObjectoptional object to save.
-
Get object from store.
Declaration
Swift
public var object: T? { get } -
Delete object from store.
Declaration
Swift
public func delete() throws -
Check if store has an object.
Declaration
Swift
public var hasObject: Bool { get }
SingleFileStore Class Reference