SingleFilesStore
open class SingleFilesStore<T> where T : Decodable, T : Encodable
SingleFilesStore
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
-
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)
Parameters
uniqueIdentifier
store’s unique identifier.
-
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 }