Drop ObjC support for KeychainStore, refactor setters for KeyValueStore

This commit is contained in:
ismailgulek
2020-07-28 18:59:01 +03:00
parent 416439d103
commit a2e2c23ccc
4 changed files with 15 additions and 17 deletions
@@ -20,9 +20,9 @@ typealias KeyValueStoreKey = String
protocol KeyValueStore {
// setters
func setData(_ value: Data?, forKey key: KeyValueStoreKey) throws
func setString(_ value: String?, forKey key: KeyValueStoreKey) throws
func setBool(_ value: Bool?, forKey key: KeyValueStoreKey) throws
func set(_ value: Data?, forKey key: KeyValueStoreKey) throws
func set(_ value: String?, forKey key: KeyValueStoreKey) throws
func set(_ value: Bool?, forKey key: KeyValueStoreKey) throws
// getters
func data(forKey key: KeyValueStoreKey) throws -> Data?
@@ -34,7 +34,6 @@ extension Keychain {
}
@objcMembers
class KeychainStore {
private var keychain: Keychain
@@ -50,7 +49,7 @@ class KeychainStore {
extension KeychainStore: KeyValueStore {
// setters
func setData(_ value: Data?, forKey key: KeyValueStoreKey) throws {
func set(_ value: Data?, forKey key: KeyValueStoreKey) throws {
guard let value = value else {
try removeObject(forKey: key)
return
@@ -59,7 +58,7 @@ extension KeychainStore: KeyValueStore {
try keychain.set(value, key: key)
}
func setString(_ value: String?, forKey key: KeyValueStoreKey) throws {
func set(_ value: String?, forKey key: KeyValueStoreKey) throws {
guard let value = value else {
try removeObject(forKey: key)
return
@@ -68,7 +67,7 @@ extension KeychainStore: KeyValueStore {
try keychain.set(value, key: key)
}
func setBool(_ value: Bool?, forKey key: KeyValueStoreKey) throws {
func set(_ value: Bool?, forKey key: KeyValueStoreKey) throws {
guard let value = value else {
try removeObject(forKey: key)
return
@@ -16,12 +16,11 @@
import Foundation
@objcMembers
class MemoryStore {
private var map: Dictionary<KeyValueStoreKey, Any> = [:]
private func set(_ value: Any?, forKey key: KeyValueStoreKey) {
private func setObject(_ value: Any?, forKey key: KeyValueStoreKey) {
if let value = value {
map[key] = value
} else {
@@ -38,16 +37,16 @@ class MemoryStore {
extension MemoryStore: KeyValueStore {
// setters
func setData(_ value: Data?, forKey key: KeyValueStoreKey) throws {
set(value, forKey: key)
func set(_ value: Data?, forKey key: KeyValueStoreKey) throws {
setObject(value, forKey: key)
}
func setString(_ value: String?, forKey key: KeyValueStoreKey) throws {
set(value, forKey: key)
func set(_ value: String?, forKey key: KeyValueStoreKey) throws {
setObject(value, forKey: key)
}
func setBool(_ value: Bool?, forKey key: KeyValueStoreKey) throws {
set(value, forKey: key)
func set(_ value: Bool?, forKey key: KeyValueStoreKey) throws {
setObject(value, forKey: key)
}
// getters