So I seem to be having some issues getting this value from the Keychain.
This is what I am using to save the password. This is called on the second view controller.
do {
try Locksmith.updateData(["password": "Boom123456"], forUserAccount: "KeychainDemo")
} catch {
print("Unable to set password")
}
When I go back to the first view controller that has the check for keychain item on:
let dictionary = Locksmith.loadDataForUserAccount("KeychainDemo")
if let passwordSaved = dictionary!["password"]?.stringValue {
print("password: \(passwordSaved)")
} else {
print("No Password")
}
When I run the app I get:
No Password
in the console. However, When I set break points on the let dictionary and then type po dictionary in the console I get this output:
Optional <Dictionary<String, AnyObject>>
Some : 1 elements
[0] : 2 elements
- .0 : "password"
- .1 : Boom123456
So it is there, Can anyone see why my code is not getting the password from the Keychain?
Looks like you're pulling your "password" string out of the dictionary incorrectly. Don't use the .stringValue function in this case. Change this line:
to