dispatch to main queue on set

This commit is contained in:
Sindre Sorhus 2024-02-11 16:42:49 +07:00
parent bde740c9b4
commit eef0df0930
1 changed files with 7 additions and 5 deletions

View File

@ -10,12 +10,14 @@ extension UserDefaults {
}
func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true {
removeObject(forKey: key)
return
}
DispatchQueue.main.async { [self] in
if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true {
removeObject(forKey: key)
return
}
set(Value.toSerializable(value), forKey: key)
set(Value.toSerializable(value), forKey: key)
}
}
public subscript<Value: Defaults.Serializable>(key: Defaults.Key<Value>) -> Value {