CodableStorage
open class CodableStorage : CodableStoring
Implementation for CodableStorage
Stores each instance as Data
in the store
using coder
for encoding/decoding.
The CodableStorage instance is not thread safe. Using directly from multiple threads can lead to unexpected behaviors.
-
Public initializer
Declaration
Swift
public init(store: DataStoring, coder: CoderProtocol = PlistCoder())
Parameters
store
dataStore which conforms to DataStoring protocol
coder
a Coder object which is able to encode and decode data. Conforms to CoderProtocol. By default it is a PlistCoder()
-
Loads data from composite store
Declaration
Swift
open func get<T>(_ type: T.Type, for key: String) throws -> T? where T : Decodable, T : Encodable
Parameters
type
the requested type, which has to conform to Codable protocol
key
a String object which identifies the data as a key
Return Value
the requested data type if the key exists, or nil if not exists
-
Inserts data to composite store
Declaration
Swift
open func put<T>(_ value: T, for key: String) throws where T : Decodable, T : Encodable
Parameters
value
the insertable value which is a type conforming Codable protocol
key
a String which identifies the value in the storage
-
Removes data for the given key in storage
Declaration
Swift
open func remove(for key: String) throws
Parameters
key
a String which identifies the data in the storage
-
Returns the Set of keys which are existing in the store
Declaration
Swift
public func keys() throws -> Set<String>
Return Value
Set of Strings as keys