jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 339 forks source link

Codable saving functionality #167

Open kevin-hv opened 3 years ago

kevin-hv commented 3 years ago

Hey! I really missed the functionality of saving objects conforming to the Codable protocol.

This code lives in an extension now in my projects. But I was wondering whether this could get into the main codebase.

Example code:

struct UserInfo : Codable {
    let firstName : String
    let lastName : String
}

KeychainWrapper.standard.set(UserInfo(firstName: "Kevin", lastName: "Varga Halász"), forKey: KeychainWrapper.Key.userInfo.rawValue)

guard let userInfo : UserInfo = KeychainWrapper.standard.codable(forKey: .userInfo) else { return }