A Swift framework for storing, retrieving, and removing generic password items in the system Keychain.
ELKeychain requires Swift 4 and Xcode 9.2.
Install with Carthage by adding the framework to your project's Cartfile.
github "Electrode-iOS/ELKeychain"
Install manually by adding ELKeychain.xcodeproj
to your project and configuring your target to link ELKeychain.framework
.
let password = "12345"
do {
try Keychain.set(password, account: "king-roland", service: "druidia-airshield")
} catch let error {
// failed to store keychain item
}
do {
if let password: String = try Keychain.get(account: "king-roland", service: "druidia-airshield") {
Airshield.unlock(password: password)
} else {
// unable to find password to unlock
}
} catch let error {
// an error occurred while retrieving the keychain item
}
do {
try Keychain.delete(account: "king-roland", service: "druidia-airshield")
} catch let error {
// an error occurred while trying to delete the keychain item
}
do {
let accessControl = try AccessControl(protection: .whenPasscodeSetThisDeviceOnly, policy: .UserPresence)
try Credential.keychain.set("12345", account: "king-roland", accessControl: accessControl)
} catch let error {
// an error occurred
}