您可以在一个forUserAccount
下存储多个键/值对吗?
try? Locksmith.saveData(["access_token" : access_token], forUserAccount: "UserData")
try? Locksmith.saveData(["email" : email!], forUserAccount: "UserData")
try? Locksmith.saveData(["markets" : market], forUserAccount: "UserData")
此代码在查找"email."
时失败。我能做到这一点的唯一方法是创建多个forUserAccount
字符串:UserData
,UserData1
,UserData3
等等。我试过updateData
但没有运气。如果forUserAccount
必须是唯一的,它的用途是什么?如果是这样的话似乎没有必要。
答案 0 :(得分:2)
let userIDNumber = userID as NSNumber
let userIDString : String = userIDNumber.stringValue
let keychainData = [_keychainEmailKey: email, _keychainPasswordKey: password, _keychainUserIDKey: userIDString]
Locksmith.updateData(keychainData, forUserAccount: email)
其中_keychainEmailKey
等是键的常量。因此forUserAccount
应该是唯一的,可能它会覆盖以前的值。
答案 1 :(得分:1)
就像@ nyekimov的答案所暗示的那样,可以为帐户存储值的字典。为了澄清,这是一段代码片段:
do
{
try Locksmith.saveData(["user": "notMyRealUsername", "password":"123456"], forUserAccount: "myUserAccount") //store it
let dictionary = Locksmith.loadDataForUserAccount("myUserAccount") //load it
print(dictionary) //let's see what we've got
}
catch
{
// handle errors here
}
帐户存在时使用try Locksmith.updateData(["user": "notMyRealUsernameEither", "password":"123456"], forUserAccount: "myUserAccount")
。