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
Expiration
option. 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
uniqueIdentifier
store’s unique identifier.
expiryDuration
optional store’s expiry duration default is .never.
-
Save object to store.
Throws
FileManager
or JSON encoding error.Declaration
Swift
public func save(_ object: T) throws
Parameters
object
object to save.
-
Save optional object (if not nil) to store.
Throws
FileManager
or JSON encoding error.Declaration
Swift
public func save(_ optionalObject: T?) throws
Parameters
optionalObject
optional 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 }