If you ever wanted to save something in Keychain without writing too much code, you are in the right place.
- iOS 12.0+
- Xcode 10.2+
- Swift 5+
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Keychain Storage into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'KeychainStorage', '~> 1.3.0'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate KeychainStorage into your Xcode project using Carthage, specify it in your Cartfile
:
github "radude89/KeychainStorage" "1.3.0"
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Once you have your Swift package set up, you can add KeychainStorage as a dependency by adding it to the dependencies
array of your Package.swift
.
dependencies: [
.package(url: "https://github.com/radude89/KeychainStorage.git", from: "1.0.0")
]
Just drag and drop into your project the following projects found in KeychainStorage
:
KeychainQueryFactory.swift
KeychainStorage.swift
KeyValueStorage.swift
Make sure you try out the small app, the example project found at: Example/KeychainStorageExample.xcworkspace
.
Build & run.
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!