Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with keychain and archiving objects #20

Open
jsm174 opened this issue May 30, 2019 · 2 comments
Open

Possible issue with keychain and archiving objects #20

jsm174 opened this issue May 30, 2019 · 2 comments
Labels

Comments

@jsm174
Copy link

jsm174 commented May 30, 2019

I believe I am having an issue when trying to get archived objects from the keychain.

They always come back as nil.

Take the following code:

        var preferences = UserDefaults.standard
        preferences["color", .archive] = UIColor.red
        let color = preferences["color", .archive]  as? UIColor
        print(color)
        
        var keychainPreferences = KeychainPreferences.sharedInstance
        keychainPreferences["color2", .archive] = UIColor.red
        let color2 = keychainPreferences["color2", .archive]  as? UIColor
        print(color2)

Results in:

Optional(UIExtendedSRGBColorSpace 1 0 0 1)
nil
@phimage phimage added the bug label May 30, 2019
@phimage
Copy link
Owner

phimage commented May 30, 2019

thanks for the report

maybe keychainPreferences["color2", .archive] return a Data

@jsm174
Copy link
Author

jsm174 commented May 30, 2019

Did a little more testing and this version seems to work:

        let keychainPreferences = KeychainPreferences.sharedInstance
        keychainPreferences.set(objectToArchive: UIColor.red, forKey: "color3")
        
        let color3 = keychainPreferences.unarchiveObject(forKey: "color3")
        print(color3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants