Add integer methods

This commit is contained in:
ismailgulek
2020-09-28 16:17:13 +03:00
parent 07e61c6e3d
commit 8a0c733a29
3 changed files with 23 additions and 0 deletions
@@ -76,6 +76,15 @@ extension KeychainStore: KeyValueStore {
try keychain.set(value, key: key)
}
func set(_ value: Int?, forKey key: KeyValueStoreKey) throws {
guard let value = value else {
try removeObject(forKey: key)
return
}
try keychain.set(String(value), key: key)
}
// getters
func data(forKey key: KeyValueStoreKey) throws -> Data? {
return try keychain.getData(key)
@@ -89,6 +98,10 @@ extension KeychainStore: KeyValueStore {
return try keychain.getBool(key)
}
func integer(forKey key: KeyValueStoreKey) throws -> Int? {
return try Int(keychain.getString(key) ?? "")
}
// remove
func removeObject(forKey key: KeyValueStoreKey) throws {
try keychain.remove(key)