Open DanielZanchi opened 10 months ago
I would like to support saving integer to keychain. would this be ok? it seems working under iOS but i would like to be sure there nothing wrong:
extension KeychainSwift { func getInt(_ key: String) -> Int? { if let data = getData(key) { do { let number = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSNumber.self, from: data) return number?.intValue } catch { print("Unarchiving error: \(error)") return nil } } else { return nil } } @discardableResult func set(_ value: Int, forKey key: String) -> Bool { let number = NSNumber(value: value) do { let data = try NSKeyedArchiver.archivedData(withRootObject: number, requiringSecureCoding: true) return set(data, forKey: key) } catch { print("Archiving error: \(error)") return false } } }
And i would use it as:
let keychain = KeychainSwift() keychain.set(1234, forKey: "test") let testNumber = keychain.getInt("test")
Sorry I don't want to add any new features to the library.
This would be really useful
@evgenyneu May I ask why you don't want to add new features?
I would like to support saving integer to keychain. would this be ok? it seems working under iOS but i would like to be sure there nothing wrong:
And i would use it as: