Keychain Storage is a simple Keychain wrapper written in Swift. If you’ve ever wanted to save something in the Keychain without writing excessive code, you’ve come to the right place!
- iOS 18.0+
- Xcode 16.0+
- Swift 6+
The Swift Package Manager is a tool for automating the distribution of Swift code, integrated into the swift
compiler.
To add KeychainStorage as a dependency, include it in the dependencies
array of your Package.swift
file:
dependencies: [
.package(url: "https://github.com/radude89/KeychainStorage.git", from: "2.0.2")
]
For manual installation, simply drag and drop the following files into your project from the KeychainStorage
directory:
KeychainQueryFactory.swift
KeychainStorage.swift
KeyValueStorage.swift
Make sure to explore the small app included in the example project found at Example/KeychainStorageExample.xcworkspace
. Build and run the project to see it in action.
import KeychainStorage
let storage = KeychainStorage(service: "com.test.service")
try? storage.set("secret", key: "myStringKey")
try? storage.set(true, key: "myBoolKey")
import KeychainStorage
let storage = KeychainStorage(service: "com.test.service")
if let myStringValue = try? storage.string(forKey: "myStringKey") {
// Do something with myStringValue
}
if let myBoolValue = try? storage.bool(forKey: "myBoolKey") {
// Do something with myBoolValue
}
import KeychainStorage
let storage = KeychainStorage(service: "com.test.service")
try? storage.removeValue(forKey: "myStringKey")
import KeychainStorage
let storage = KeychainStorage(service: "com.test.service")
try? storage.removeAll()
KeychainStorage is released under the MIT license. See LICENSE for details.
KeychainStorage is developed as an open source project. I encourage everyone to contribute.
Please do make pull requests if you have suggestions or ideas of improvement.
Thanks!