Remove store value when set value is nil
Fixes crash on removing active profile when current, due to setting nil activeProfileId in UserDefaults.
This commit is contained in:
parent
ebe8ae3d29
commit
3e8a49c970
|
@ -40,7 +40,7 @@ extension KeyStoreDomainLocation {
|
|||
}
|
||||
|
||||
public protocol KeyValueStore {
|
||||
func setValue<L: KeyStoreLocation, V>(_ value: V, forLocation location: L)
|
||||
func setValue<L: KeyStoreLocation, V>(_ value: V?, forLocation location: L)
|
||||
|
||||
func value<L: KeyStoreLocation, V>(forLocation location: L) -> V?
|
||||
|
||||
|
|
|
@ -32,7 +32,11 @@ public struct UserDefaultsStore: KeyValueStore {
|
|||
self.defaults = defaults
|
||||
}
|
||||
|
||||
public func setValue<L: KeyStoreLocation, V>(_ value: V, forLocation location: L) {
|
||||
public func setValue<L: KeyStoreLocation, V>(_ value: V?, forLocation location: L) {
|
||||
guard let value = value else {
|
||||
defaults.removeObject(forKey: location.key)
|
||||
return
|
||||
}
|
||||
defaults.setValue(value, forKey: location.key)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue