I’d like to share a new library: SwiftConfigs
It provides a unified, type-safe API for small key-value storage systems (UserDefaults, Keychain, environment variables, in-memory, iCloud key-value store, custom backends, etc.).
Instead of juggling different APIs, you define strongly-typed keys once and access them the same way across all backends:
public extension Configs.Keys {
var apiToken: RWKey<String?> {
RWKey("api-token", in: .secure, default: nil)
}
var serverURL: ROKey<String> {
ROKey("SERVER_URL", in: .environment, default: "https://api.example.com")
}
}
let configs = Configs()
// Direct API
configs.apiToken = "new-token"
print(configs.serverURL)
// --- Property wrappers ---
// 1. By keyPath
struct Session {
@RWConfig(\.apiToken) var apiToken
}
var session = Session()
session.apiToken = "wrapped-token"
print(session.apiToken)
// 2. Directly with a key
struct Environment {
@ROConfig("SERVER_URL", in: .environment) var serverURL = "https://api.example.com"
}
let env = Environment()
print(env.serverURL)
Highlights:
-
Works with UserDefaults, Keychain, NSUbiquitousKeyValueStore, in-memory, and environment variables out of the box
-
Custom backends supported (example: Firebase Remote Configs)
-
Type-safe keys for any Codable type
-
Per-key customization (store, transformer, migration)
-
Property wrappers and async/await support
-
Change observation via callbacks or async sequences
-
Migration helpers and multiplex stores
-
Stores are abstracted by categories for flexibility, testing, and previews
-
You can override a category with a specific store when needed