From 0f5a23fcbd83eb72f6d405aa85bbfacaffb99b03 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 17 Apr 2023 20:48:39 +0800 Subject: [PATCH] Tweaks --- Sources/Defaults/Defaults+AnySerializable.swift | 2 +- Sources/Defaults/Defaults+Extensions.swift | 1 + Sources/Defaults/Defaults.swift | 2 +- Sources/Defaults/Observation.swift | 4 ++-- Sources/Defaults/Utilities.swift | 4 ++-- Tests/DefaultsTests/DefaultsCustomBridgeTests.swift | 2 +- Tests/DefaultsTests/DefaultsMigrationTests.swift | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/Defaults/Defaults+AnySerializable.swift b/Sources/Defaults/Defaults+AnySerializable.swift index 851feb6..17010ab 100644 --- a/Sources/Defaults/Defaults+AnySerializable.swift +++ b/Sources/Defaults/Defaults+AnySerializable.swift @@ -33,7 +33,7 @@ extension Defaults { var value: Any public static let bridge = AnyBridge() - init(value: T?) { + init(value: (some Any)?) { self.value = value ?? () } diff --git a/Sources/Defaults/Defaults+Extensions.swift b/Sources/Defaults/Defaults+Extensions.swift index 51a6e4f..17a2afc 100644 --- a/Sources/Defaults/Defaults+Extensions.swift +++ b/Sources/Defaults/Defaults+Extensions.swift @@ -104,6 +104,7 @@ extension Defaults.Serializable where Self: Codable & RawRepresentable & Default extension Defaults.Serializable where Self: RawRepresentable { public static var bridge: Defaults.RawRepresentableBridge { Defaults.RawRepresentableBridge() } } + extension Defaults.Serializable where Self: NSSecureCoding & NSObject { public static var bridge: Defaults.NSSecureCodingBridge { Defaults.NSSecureCodingBridge() } } diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index a14ca85..6fa37d6 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -130,7 +130,7 @@ extension Defaults { /** Create a key with a dynamic default value. - + This can be useful in cases where you cannot define a static default value as it may change during the lifetime of the app. ```swift diff --git a/Sources/Defaults/Observation.swift b/Sources/Defaults/Observation.swift index 7539fe0..858a75c 100644 --- a/Sources/Defaults/Observation.swift +++ b/Sources/Defaults/Observation.swift @@ -175,7 +175,7 @@ extension Defaults { guard selfObject == object as? NSObject, - let change = change + let change else { return } @@ -265,7 +265,7 @@ extension Defaults { guard object is UserDefaults, - let change = change + let change else { return } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index ecdf4ea..aaaee5e 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -168,7 +168,7 @@ extension Defaults { @usableFromInline internal static func isValidKeyPath(name: String) -> Bool { // The key must be ASCII, not start with @, and cannot contain a dot. - return !name.starts(with: "@") && name.allSatisfy { $0 != "." && $0.isASCII } + !name.starts(with: "@") && name.allSatisfy { $0 != "." && $0.isASCII } } } @@ -259,7 +259,7 @@ internal let dynamicSharedObject: UnsafeMutableRawPointer = { @_transparent @usableFromInline internal func runtimeWarn( - _ condition: @autoclosure() -> Bool, _ message: @autoclosure () -> String + _ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String ) { #if DEBUG #if canImport(OSLog) diff --git a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift index 29bc395..5da6db9 100644 --- a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift +++ b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift @@ -49,7 +49,7 @@ extension PlainHourMinuteTimeRange: Defaults.Serializable { typealias Serializable = [PlainHourMinuteTime] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } diff --git a/Tests/DefaultsTests/DefaultsMigrationTests.swift b/Tests/DefaultsTests/DefaultsMigrationTests.swift index fd602a6..5f30efa 100644 --- a/Tests/DefaultsTests/DefaultsMigrationTests.swift +++ b/Tests/DefaultsTests/DefaultsMigrationTests.swift @@ -249,7 +249,7 @@ extension CodableEnumForm: Defaults.CodableType { typealias NativeForm = EnumForm } -private func setCodable(forKey keyName: String, data: Value) { +private func setCodable(forKey keyName: String, data: some Codable) { guard let text = try? JSONEncoder().encode(data), let string = String(data: text, encoding: .utf8)