Keychain

public actor Keychain<T> : Storage where T : Decodable, T : Encodable, T : Sendable

A storage for storing Codable objects in the Keychain

  • Initializer for Keychain

    Declaration

    Swift

    public init(account: String, encryptor: Encryptor = NoEncryptor())

    Parameters

    account

    String indicating the item’s account(key) name.

    encryptor

    Encryptor for encrypting stored data. Default value is NoEncryptor()

  • save(item:) Asynchronous

    Saves the given item in the keychain.

    Declaration

    Swift

    public func save(item: T) async throws

    Parameters

    item

    The item to save.

  • get() Asynchronous

    Retrieves the item from the keychain.

    Declaration

    Swift

    public func get() async throws -> T?

    Return Value

    The item if it exists, nil otherwise.

  • delete() Asynchronous

    Deletes the item from memory.

    Declaration

    Swift

    public func delete() async throws