Skip to content

Commit

Permalink
Work around Swift bug in Xcode 16
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 11, 2024
1 parent 3b770e2 commit 5434b04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Defaults/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension Defaults {

super.init(name: name, suite: suite)

if (defaultValue as? _DefaultsOptionalProtocol)?._defaults_isNil == true {
guard !isNil(defaultValue) else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension UserDefaults {
}

func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true {
guard !isNil(value) else {
removeObject(forKey: key)
return
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,14 @@ func runtimeWarn(
#endif
#endif
}


@usableFromInline
func isNil(_ value: Any) -> Bool {
switch value {
case Optional<Any>.none:
return true
default:
return false
}
}

0 comments on commit 5434b04

Please sign in to comment.