OZUserDefaultsStorageAdapter
public final actor OZUserDefaultsStorageAdapter : OZStorageAdapter
Persistent OZStorageAdapter backed by an isolated UserDefaults suite.
Stores credential and session payloads as UTF-8 JSON strings under stable keys:
cred_<credentialId>for individual stored credentials,credential_indexfor the JSON-encoded list of known credential IDs,session_currentfor the active session.
The adapter scopes every read and write to a UserDefaults(suiteName:)
instance so multiple adapter instances configured with different suites do
not interfere with one another. Stored credentials contain only public
key material plus metadata, so UserDefaults provides adequate isolation
for typical use cases. Applications requiring stronger at-rest protection
should use OZKeychainStorageAdapter instead.
Thread safety is provided by Swift Concurrency actor isolation, which
serializes all operations against the underlying UserDefaults instance.
Example:
let storage = try OZUserDefaultsStorageAdapter()
try await storage.save(credential: credential)
let loaded = try await storage.get(credentialId: credential.credentialId)
Important
Not encrypted at rest.UserDefaults persists payloads to a
plaintext property-list file in the application container; on a
jailbroken device or via an unencrypted iTunes/Finder backup, the
contents are recoverable. The credentials persisted by this adapter
contain only public-key material and non-secret metadata; applications
storing session data or anything sensitive should use
OZKeychainStorageAdapter instead.
-
Default suite name passed to
UserDefaults(suiteName:).Consumers can override this via the initializer to scope the adapter to a different suite — useful when multiple isolated stores must coexist within the same process.
Declaration
Swift
public static let defaultSuiteName: String -
Initializes a new
OZUserDefaultsStorageAdapterscoped tosuiteName.Throws
SmartAccountStorageException.WriteFailedwhenUserDefaults(suiteName:)returnsnil. This happens when the supplied suite name is reserved (for example the empty string) or otherwise rejected by the system.Declaration
Swift
public init(suiteName: String = OZUserDefaultsStorageAdapter.defaultSuiteName) throwsParameters
suiteNameName of the
UserDefaultssuite to use as the backing store. Defaults toOZUserDefaultsStorageAdapter.defaultSuiteName. -
save(credential:Asynchronous) Declaration
Swift
public func save(credential: OZStoredCredential) async throws -
get(credentialId:Asynchronous) Declaration
Swift
public func get(credentialId: String) async throws -> OZStoredCredential? -
getByContract(contractId:Asynchronous) Declaration
Swift
public func getByContract(contractId: String) async throws -> [OZStoredCredential] -
getAll()AsynchronousDeclaration
Swift
public func getAll() async throws -> [OZStoredCredential] -
delete(credentialId:Asynchronous) Declaration
Swift
public func delete(credentialId: String) async throws -
update(credentialId:Asynchronousupdates: ) Declaration
Swift
public func update(credentialId: String, updates: OZStoredCredentialUpdate) async throws -
clear()AsynchronousDeclaration
Swift
public func clear() async throws -
saveSession(_:Asynchronous) Declaration
Swift
public func saveSession(_ session: OZStoredSession) async throws -
getSession()AsynchronousDeclaration
Swift
public func getSession() async throws -> OZStoredSession? -
clearSession()AsynchronousDeclaration
Swift
public func clearSession() async throws
View on GitHub
Install in Dash