A lightweight and thread-safe persistent key-value storage built on top of SwiftData.
| Platform | Minimum Target Version |
|---|---|
| iOS | 18.0 |
| macOS | 15.0 |
| watchOS | 11.0 |
| visionOS | 2.0 |
| tvOS | 18.0 |
To install this package, use Swift Package Manager.
- Open Xcode and in the menu bar, select File > Add Package Dependencies.
- In the dialog box, paste
https://github.com/nealarch01/KVStorein the search bar at the top right. - Lastly, add the package to your app's target(s).
// Create a KVStore instance
let store = KVStore()
// Store simple values
await store.setValue(key: "username", value: "john_doe")
await store.setValue(key: "user_id", value: 12345)
await store.setValue(key: "is_premium", value: true)
// Retrieve values
let username = await store.getValue(String.self, key: "username") // "john_doe"
let userId = await store.getValue(Int.self, key: "user_id") // 12345
let isPremium = await store.getValue(Bool.self, key: "is_premium") // truestruct User: Codable {
let id: Int
let name: String
let email: String
}
// Store a custom object
let user = User(id: 1, name: "Alice", email: "[email protected]")
await store.setValue(key: "current_user", value: user)
// Retrieve the object
if let savedUser = await store.getValue(User.self, key: "current_user") {
print("Welcome back, \(savedUser.name)!")
}// Store arrays
let favorites = ["apple", "banana", "orange"]
await store.setValue(key: "favorite_fruits", value: favorites)
// Retrieve arrays
let savedFavorites = await store.getValue([String].self, key: "favorite_fruits")
// Store dictionaries
let settings = ["theme": "dark", "language": "en"]
await store.setValue(key: "app_settings", value: settings)All contributions are welcome!
- Ideas/Bugs: If you have an idea for a new feature, or encountered a bug, open a new Issue. Describe it clearly and include any steps to reproduce if it's a bug.
- Pull Requests: Keep them simple and handle one feature/bug at a time. Additionally, make sure the title and description is clear and descriptive.