Summary: - Sources: update Documentation.docc, Services - Docs: update docs for README Stats: - 4 files changed, 15 insertions(+), 2 deletions(-)
1.5 KiB
1.5 KiB
Getting Started
Follow this guide to define keys, configure LocalData, and register catalogs for auditing.
1) Define keys
Keys are static, typed constants. Do not use dynamic key names.
import LocalData
extension StorageKey where Value == String {
static let userToken = StorageKey(
name: "user_token",
domain: .keychain(service: "com.myapp"),
owner: "Auth",
description: "Current user auth token."
)
}
2) Configure the router (optional)
Set defaults once at app launch to avoid repeating service identifiers.
let storageConfig = StorageConfiguration(
defaultKeychainService: "com.myapp.keychain",
defaultAppGroupIdentifier: "group.com.myapp"
)
await StorageRouter.shared.updateStorageConfiguration(storageConfig)
3) Register catalogs
Catalogs are mandatory if you want auditing and duplicate detection.
Important
Once any catalog is registered, all storage operations require the key to be present in a registered catalog. Unregistered keys will throw
StorageError.unregisteredKey.
struct AuthCatalog: StorageKeyCatalog {
let allKeys: [AnyStorageKey] = [
.key(StorageKey.userToken)
]
}
try await StorageRouter.shared.registerCatalog(AuthCatalog())
4) Store and read values
try await StorageRouter.shared.set("token", for: .userToken)
let token = try await StorageRouter.shared.get(.userToken)
Next steps
- Read doc:KeyAndCatalogDiscipline to avoid audit gaps.
- Add migrations in doc:Migrations.