A thin wrapper on Swift's Keychain functionality for managing key-value pairs securely. Inspired by UserDefaults.
- Store, retrieve, and delete key-value pairs securely in the Keychain
- Supports
Codable
types for easy encoding and decoding
To integrate KVKeychain
into your project using Swift Package Manager, add it to the dependencies in your Package.swift
:
dependencies: [
.package(url: "https://github.com/ssadel/KVKeychain.git", .upToNextMinor(from: "1.0.1"))
]
After adding the package, import Keychain
import Keychain
Then you can use any of the 3 methods on the KVKeychain class
let key: String = "user_id"
let value: String = "123456"
// Set value
try? KVKeychain.set(value, forKey: key)
// Get value
guard let value: String = try? KVKeychain.getValue(forKey: key) else { return }
// Update value
let newValue: String = "654321"
try? KVKeychain.set(newValue, forKey: key)
// Remove a key-value pair
try? KVKeychain.removeObject(forKey: key)