mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
Change KeyValueStore api
This commit is contained in:
@@ -17,11 +17,11 @@
|
||||
import Foundation
|
||||
|
||||
@objcMembers
|
||||
class MemoryStore: KeyValueStore {
|
||||
class MemoryStore {
|
||||
|
||||
private var map: Dictionary<KeyValueStoreKey, Any> = [:]
|
||||
|
||||
func set(_ value: Any?, forKey key: KeyValueStoreKey) {
|
||||
private func set(_ value: Any?, forKey key: KeyValueStoreKey) {
|
||||
if let value = value {
|
||||
map[key] = value
|
||||
} else {
|
||||
@@ -29,10 +29,41 @@ class MemoryStore: KeyValueStore {
|
||||
}
|
||||
}
|
||||
|
||||
func object(forKey key: KeyValueStoreKey) -> Any? {
|
||||
private func object(forKey key: KeyValueStoreKey) -> Any? {
|
||||
return map[key]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MemoryStore: KeyValueStore {
|
||||
|
||||
// setters
|
||||
func setData(_ value: Data?, forKey key: KeyValueStoreKey) throws {
|
||||
set(value, forKey: key)
|
||||
}
|
||||
|
||||
func setString(_ value: String?, forKey key: KeyValueStoreKey) throws {
|
||||
set(value, forKey: key)
|
||||
}
|
||||
|
||||
func setBool(_ value: Bool?, forKey key: KeyValueStoreKey) throws {
|
||||
set(value, forKey: key)
|
||||
}
|
||||
|
||||
// getters
|
||||
func data(forKey key: KeyValueStoreKey) throws -> Data? {
|
||||
return object(forKey: key) as? Data
|
||||
}
|
||||
|
||||
func string(forKey key: KeyValueStoreKey) throws -> String? {
|
||||
return object(forKey: key) as? String
|
||||
}
|
||||
|
||||
func bool(forKey key: KeyValueStoreKey) throws -> Bool? {
|
||||
return object(forKey: key) as? Bool
|
||||
}
|
||||
|
||||
// remove
|
||||
func removeObject(forKey key: KeyValueStoreKey) {
|
||||
map.removeValue(forKey: key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user