Locksmith icon indicating copy to clipboard operation
Locksmith copied to clipboard

Not being able to retrieve values

Open nunogoncalves opened this issue 8 years ago • 5 comments

Hi,

Just updated to the 2.0 version and now I'm unable to retrieve any values. Am I missing something?

I'm Using Xcode 8, and swift 3. Deployment target iOS 10.0

Problem:

Locksmith.saveData(data: ["some_key": "some_value"], forUserAccount: "user_account")

Locksmith.loadDataForUserAccount(userAccount: "user_account") => nil

nunogoncalves avatar Sep 18 '16 22:09 nunogoncalves

I got the same result. I'm also on an updated Xcode 8; deployment target iOS 10.0; using:

$ swift --version
Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
Target: x86_64-apple-macosx10.9

I've put Locksmith.saveData(data:forUserAccount:) in viewDidLoad(). And then I'm getting nil when attempting Locksmith.loadDataForUserAccount(userAccount:) in a button clicked action.

mtso avatar Sep 19 '16 05:09 mtso

Ah, found my solution here: Issue #146 Which points to: http://stackoverflow.com/a/38543243/2684355 Needed to enable Keychain Sharing in Targets > Capabilities.

Not sure if this will also work for @nunogoncalves?

mtso avatar Sep 19 '16 05:09 mtso

This workaround also worked for me, which is enough to unblock my work using this library, but I think it is still a bug in Locksmith. Will submit a PR if I end up fixing it myself, probably something lost in translation when migrating to Swift 3. Had some problems myself related to the distinction between NSDictionary, Dictionary<String,AnyObject!> and Dictionary<String,AnyObject>; which caused code paths to fail in unexpected ways.

The documentation README also needs updating for Swift 3 method call syntax, and when used as in the initial bug report in a simple fresh project reproduces the bug. When using updateData rather than saveData, a LocksmithError.undefined is thrown.

Hope this additional information helps!

mensly avatar Sep 19 '16 06:09 mensly

@mtso yes that worked. Thanks. :)

nunogoncalves avatar Sep 19 '16 08:09 nunogoncalves

I had this same issue and @mtso's suggestion fixes it. Spent a long while checking my code to make sure it wasn't an issue from the conversion to Swift 3 that I just did. If it is an intentional requirement or not, at the least it should result in an error so it's known what is wrong.

kooliokey avatar Dec 02 '16 05:12 kooliokey