From 025a893b8906a0f40db9103b9b447824449dd3c9 Mon Sep 17 00:00:00 2001 From: Keita Watanabe Date: Sat, 13 Jul 2024 19:13:28 +0900 Subject: [PATCH 1/2] fix existential any --- Sources/Defaults/Defaults+iCloud.swift | 4 ++-- Sources/Defaults/Defaults.swift | 2 +- Sources/Defaults/Observation.swift | 6 +++--- Sources/Defaults/UserDefaults.swift | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Defaults/Defaults+iCloud.swift b/Sources/Defaults/Defaults+iCloud.swift index 6a38ee9..2f24c27 100644 --- a/Sources/Defaults/Defaults+iCloud.swift +++ b/Sources/Defaults/Defaults+iCloud.swift @@ -209,7 +209,7 @@ Manages `Defaults.Keys` between the locale and remote storage. Depending on the storage, `Defaults.Keys` will be represented in different forms due to storage limitations of the remote storage. The remote storage imposes a limitation of 1024 keys. Therefore, we combine the recorded timestamp and data into a single key. Unlike remote storage, local storage does not have this limitation. Therefore, we can create a separate key (with `defaultsSyncKey` suffix) for the timestamp record. */ final class iCloudSynchronizer { - init(remoteStorage: DefaultsKeyValueStore) { + init(remoteStorage: any DefaultsKeyValueStore) { self.remoteStorage = remoteStorage registerNotifications() remoteStorage.synchronize() @@ -231,7 +231,7 @@ final class iCloudSynchronizer { /** A remote key value storage. */ - private let remoteStorage: DefaultsKeyValueStore + private let remoteStorage: any DefaultsKeyValueStore /** A FIFO queue used to serialize synchronization on keys. diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 1cb2ee7..dfa4731 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 { + if (defaultValue as? (any _DefaultsOptionalProtocol))?._defaults_isNil == true { return } diff --git a/Sources/Defaults/Observation.swift b/Sources/Defaults/Observation.swift index 683ef59..0d9a98d 100644 --- a/Sources/Defaults/Observation.swift +++ b/Sources/Defaults/Observation.swift @@ -85,7 +85,7 @@ extension Defaults { } private static var preventPropagationThreadDictionaryKey: String { - "\(type(of: Observation.self))_threadUpdatingValuesFlag" + "\(type(of: (any Observation).self))_threadUpdatingValuesFlag" } /** @@ -460,7 +460,7 @@ extension Defaults { _ key: Key, options: ObservationOptions = [.initial], handler: @escaping (KeyChange) -> Void - ) -> Observation { + ) -> some Observation { let observation = UserDefaultsKeyObservation(object: key.suite, key: key.name) { change in handler( KeyChange(change: change, defaultValue: key.defaultValue) @@ -490,7 +490,7 @@ extension Defaults { keys: _AnyKey..., options: ObservationOptions = [.initial], handler: @escaping () -> Void - ) -> Observation { + ) -> some Observation { let pairs = keys.map { (suite: $0.suite, key: $0.name) } diff --git a/Sources/Defaults/UserDefaults.swift b/Sources/Defaults/UserDefaults.swift index 5e1bc2f..daf8c40 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 { + if (value as? (any _DefaultsOptionalProtocol))?._defaults_isNil == true { removeObject(forKey: key) return } From a4a8201891583d94e6054d3d469bd74ccfe2f6b8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 14 Jul 2024 01:51:15 +0200 Subject: [PATCH 2/2] Update UserDefaults.swift --- Sources/Defaults/UserDefaults.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Defaults/UserDefaults.swift b/Sources/Defaults/UserDefaults.swift index daf8c40..6dd82e0 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? (any _DefaultsOptionalProtocol))?._defaults_isNil == true { + if (value as? (any _DefaultsOptionalProtocol))?._defaults_isNil == true { removeObject(forKey: key) return }