Swift + Locksmith:未存储钥匙串值 [英] Swift + Locksmith: Not getting stored Keychain Value

查看:130
本文介绍了Swift + Locksmith:未存储钥匙串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我似乎在从钥匙串获取此值时遇到一些问题.

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:

没有密码

在控制台中

.但是,当我在 let字典上设置断点,然后在控制台中键入 po字典时,我得到以下输出:

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?

推荐答案

好像您是从字典中错误地提取了密码"字符串.在这种情况下,请勿使用.stringValue函数.更改此行:

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:

if let passwordSaved = dictionary!["password"]?.stringValue {

if let passwordSaved = dictionary!["password"] as? String {

这篇关于Swift + Locksmith:未存储钥匙串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆