PROTOCOL

Storage

public protocol Storage

A Storage protocol defines the operations that are available for any class that implements this protocol. A class that implements the Storage protocol is responsible for persisting and managing the value of a sensitive piece of data through its lifecycle. The value should not be meaningful to the implementation of the Storage protocol, but instead be treated as an opaque String.

The default implementation of the Storage protocol uses the Keychain to persist its values. This implementation is internally used.

Methods

read(key:)

func read(key: String) throws -> Data?

Read and return the value with a given key from the Storage. When found, it is wrapped and returned in a Data instance. If there is no entry for the key, then nil is returned.

Parameters

Name Description
key the name of the entry to look up in the Storage.

write(key:data:)

func write(key: String, data: Data) throws

Write an entry with a given key and data to the Storage.

When the entry already exists, it will overwrite an existing entry with the new value.

Parameters

Name Description
key the name of the entry to write in the Storage.
data the Data representation of the value to write to the entry with the name of the key parameter

delete(key:)

func delete(key: String) throws

Delete the entry with the name key from the Storage. If there is no entry for the key, then it is left to the Storage implementation to return with or without an error.

Parameters

Name Description
key the name of the entry to delete from the Storage.