From 5434b04cb418a6975b5d149edb9ae1da4eb0d9a9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 11 Jun 2024 16:12:24 +0200 Subject: [PATCH] Work around Swift bug in Xcode 16 --- Sources/Defaults/Defaults.swift | 2 +- Sources/Defaults/UserDefaults.swift | 2 +- Sources/Defaults/Utilities.swift | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 1cb2ee7..0930039 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -126,7 +126,7 @@ extension Defaults { super.init(name: name, suite: suite) - if (defaultValue as? _DefaultsOptionalProtocol)?._defaults_isNil == true { + guard !isNil(defaultValue) else { return } diff --git a/Sources/Defaults/UserDefaults.swift b/Sources/Defaults/UserDefaults.swift index 5e1bc2f..11a3433 100644 --- a/Sources/Defaults/UserDefaults.swift +++ b/Sources/Defaults/UserDefaults.swift @@ -10,7 +10,7 @@ extension UserDefaults { } func _set(_ key: String, to value: Value) { - if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true { + guard !isNil(value) else { removeObject(forKey: key) return } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index 07a871f..08872da 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -458,3 +458,14 @@ func runtimeWarn( #endif #endif } + + +@usableFromInline +func isNil(_ value: Any) -> Bool { + switch value { + case Optional.none: + return true + default: + return false + } +}