Work around Swift bug in Xcode 16

This commit is contained in:
Sindre Sorhus 2024-06-11 16:12:24 +02:00
parent 3b770e22df
commit 5434b04cb4
3 changed files with 13 additions and 2 deletions

View File

@ -126,7 +126,7 @@ extension Defaults {
super.init(name: name, suite: suite) super.init(name: name, suite: suite)
if (defaultValue as? _DefaultsOptionalProtocol)?._defaults_isNil == true { guard !isNil(defaultValue) else {
return return
} }

View File

@ -10,7 +10,7 @@ extension UserDefaults {
} }
func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) { func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true { guard !isNil(value) else {
removeObject(forKey: key) removeObject(forKey: key)
return return
} }

View File

@ -458,3 +458,14 @@ func runtimeWarn(
#endif #endif
#endif #endif
} }
@usableFromInline
func isNil(_ value: Any) -> Bool {
switch value {
case Optional<Any>.none:
return true
default:
return false
}
}