mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 23:18:27 +02:00
Add integer methods
This commit is contained in:
@@ -23,11 +23,13 @@ protocol KeyValueStore {
|
||||
func set(_ value: Data?, forKey key: KeyValueStoreKey) throws
|
||||
func set(_ value: String?, forKey key: KeyValueStoreKey) throws
|
||||
func set(_ value: Bool?, forKey key: KeyValueStoreKey) throws
|
||||
func set(_ value: Int?, forKey key: KeyValueStoreKey) throws
|
||||
|
||||
// getters
|
||||
func data(forKey key: KeyValueStoreKey) throws -> Data?
|
||||
func string(forKey key: KeyValueStoreKey) throws -> String?
|
||||
func bool(forKey key: KeyValueStoreKey) throws -> Bool?
|
||||
func integer(forKey key: KeyValueStoreKey) throws -> Int?
|
||||
|
||||
// remove
|
||||
func removeObject(forKey key: KeyValueStoreKey) throws
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -49,6 +49,10 @@ extension MemoryStore: KeyValueStore {
|
||||
setObject(value, forKey: key)
|
||||
}
|
||||
|
||||
func set(_ value: Int?, forKey key: KeyValueStoreKey) throws {
|
||||
setObject(value, forKey: key)
|
||||
}
|
||||
|
||||
// getters
|
||||
func data(forKey key: KeyValueStoreKey) throws -> Data? {
|
||||
return object(forKey: key) as? Data
|
||||
@@ -62,6 +66,10 @@ extension MemoryStore: KeyValueStore {
|
||||
return object(forKey: key) as? Bool
|
||||
}
|
||||
|
||||
func integer(forKey key: KeyValueStoreKey) throws -> Int? {
|
||||
return object(forKey: key) as? Int
|
||||
}
|
||||
|
||||
// remove
|
||||
func removeObject(forKey key: KeyValueStoreKey) {
|
||||
map.removeValue(forKey: key)
|
||||
|
||||
Reference in New Issue
Block a user