SwiftKeychainWrapper icon indicating copy to clipboard operation
SwiftKeychainWrapper copied to clipboard

XCTestCase: set NewValue return False

Open javierbc121086 opened this issue 4 years ago • 2 comments

Hi, I try save string data on keychain, however, the function set return False.

Any idea ?

I post the code:

    public static var tokenSession: String {
        set {
            KeychainWrapper.standard.set(
                newValue,
                forKey: "sm_token_session_key",
                withAccessibility: .always,
                isSynchronizable: true
            )
        }
        get {
            KeychainWrapper.standard.string(
                forKey: "sm_token_session_key",
                withAccessibility: .always,
                isSynchronizable: true
            ) ?? .empty
        }
    }

javierbc121086 avatar Jan 20 '22 18:01 javierbc121086

@javierbc121086 it might work if you remove isSynchronizable. I'm guessing there's some info plist permission that needs to be added for sync to work. Maybe https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps?

mrmurphy avatar Aug 27 '22 13:08 mrmurphy

Ah note, there must be something else going on here. The reason I wasn't getting anything back in my code was that I wasn't passing isSynchronizable to both the getter and the setter, just the setter. They both need it.

mrmurphy avatar Aug 27 '22 14:08 mrmurphy