CodableStoring
public protocol CodableStoring : AnyObject
CodableStoring API Implementers has to store instances of classes conforming to the Codable protocol associated with a given key.
-
Generic function to get a type specific value from the datastore. The type has to conform to Codable protocol
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func get<T>(_ type: T.Type, for: String) throws -> T? where T : Decodable, T : Encodable
Parameters
type
the Codable type itself. For example: “Data.self”
key
a String which is the key of the value
Return Value
ans instance of given type or nil
-
Generic function to insert a type specific value to the datastore. The type has to conform to Codable protocol
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func put<T>(_ value: T, for: String) throws where T : Decodable, T : Encodable
Parameters
value
the instance which has to be stored
key
a String type, which will be the key in the store
-
Generic function to remove a type specific value from the datastore. The type has to conform to Codable protocol
note: Check Apple documentation for further information about Codable protocol: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types
Declaration
Swift
func remove(for: String) throws
Parameters
key
the of the datavalue to remove
-
Returns the keys which are currently in the datastore
Declaration
Swift
func keys() throws -> Set<String>
Return Value
a Set of Strings containing the existing keys in the store