phimage / Prephirences

Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults
MIT License
573 stars 35 forks source link

store struct not working #28

Open niskah-media opened 1 month ago

niskah-media commented 1 month ago

I'm trying to store struct object but not work.

struct InstagramApiUser: Codable {
    var access_token: String
    var user_id: Int
}

storing with:

let json = try JSONDecoder().decode(InstagramApiUser.self, from: data)
KeychainPreferences.sharedInstance[InstagramClient.keychain_api_user_key, .archive] = json

retrieving with:

         if let user = self.keychain.object(forKey: InstagramClient.keychain_api_user_key) as? InstagramApiUser {
             print("- OAuth2 user api: \(String(describing: self.user_api))")
         } 
phimage commented 1 month ago

hi have you add a breakpoint, see the value returned by object function? (maybe before read the code...)

https://github.com/phimage/Prephirences/blob/3a42074d540c09018cd0699eced43905847a2381/Sources/PrephirenceType%2BCodable.swift#L2