From bc1af5d8728db4957ba3eac0f944362654247683 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 5 Sep 2022 14:05:41 +0700 Subject: [PATCH] Upgrade to Swit 5.7 --- .github/workflows/main.yml | 6 +- Package.swift | 2 +- Sources/Defaults/Defaults+Bridge.swift | 77 +++++++------------ Sources/Defaults/Defaults+Protocol.swift | 4 +- .../Migration/v5/Migration+Extensions.swift | 2 +- .../Migration/v5/Migration+Protocol.swift | 3 +- .../Migration/v5/Migration+UserDefaults.swift | 6 +- Sources/Defaults/Observation+Combine.swift | 2 +- Sources/Defaults/Observation.swift | 2 +- Sources/Defaults/SwiftUI.swift | 8 +- Sources/Defaults/Utilities.swift | 4 +- ...DefaultsCollectionCustomElementTests.swift | 4 +- .../DefaultsCustomBridgeTests.swift | 4 +- .../DefaultsMigrationTests.swift | 16 ++-- Tests/DefaultsTests/DefaultsRangeTests.swift | 4 +- ...DefaultsSetAlgebraCustomElementTests.swift | 4 +- .../DefaultsSetAlgebraTests.swift | 2 +- .../DefaultsTests+Workaround.swift | 38 --------- migration.md | 8 +- readme.md | 36 +-------- workaround.md | 50 ------------ 21 files changed, 70 insertions(+), 212 deletions(-) delete mode 100644 Tests/DefaultsTests/DefaultsTests+Workaround.swift delete mode 100644 workaround.md diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ecfa450..3786561 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,12 +4,12 @@ on: - pull_request jobs: test: - runs-on: macos-11 + runs-on: macos-12 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: swift test lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: norio-nomura/action-swiftlint@3.2.1 diff --git a/Package.swift b/Package.swift index a8f7f60..c0934cd 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.7 import PackageDescription let package = Package( diff --git a/Sources/Defaults/Defaults+Bridge.swift b/Sources/Defaults/Defaults+Bridge.swift index 6dddbac..e2b7b4d 100644 --- a/Sources/Defaults/Defaults+Bridge.swift +++ b/Sources/Defaults/Defaults+Bridge.swift @@ -8,7 +8,7 @@ import UIKit extension Defaults.CodableBridge { public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -25,11 +25,11 @@ extension Defaults.CodableBridge { } public func deserialize(_ object: Serializable?) -> Value? { - guard let jsonString = object else { + guard let object else { return nil } - return [Value].init(jsonString: "[\(jsonString)]")?.first + return [Value].init(jsonString: "[\(object)]")?.first } } @@ -37,30 +37,21 @@ extension Defaults.CodableBridge { Any `Value` that conforms to `Codable` and `Defaults.Serializable` will use `CodableBridge` to do the serialization and deserialization. */ extension Defaults { - public struct TopLevelCodableBridge: CodableBridge { - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - } + public struct TopLevelCodableBridge: CodableBridge {} } /** `RawRepresentableCodableBridge` is needed because, for example, with `enum SomeEnum: String, Codable, Defaults.Serializable`, the compiler will be confused between `RawRepresentableBridge` and `TopLevelCodableBridge`. */ extension Defaults { - public struct RawRepresentableCodableBridge: CodableBridge { - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - } + public struct RawRepresentableCodableBridge: CodableBridge {} } /** This exists to avoid compiler ambiguity. */ extension Defaults { - public struct CodableNSSecureCodingBridge: CodableBridge { - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - } + public struct CodableNSSecureCodingBridge: CodableBridge {} } extension Defaults { @@ -74,19 +65,16 @@ extension Defaults { public typealias Value = Value public typealias Serializable = Value.RawValue - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - public func serialize(_ value: Value?) -> Serializable? { value?.rawValue } public func deserialize(_ object: Serializable?) -> Value? { - guard let rawValue = object else { + guard let object else { return nil } - return Value(rawValue: rawValue) + return Value(rawValue: object) } } } @@ -96,24 +84,21 @@ extension Defaults { public typealias Value = Value public typealias Serializable = Data - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - public func serialize(_ value: Value?) -> Serializable? { - guard let object = value else { + guard let value else { return nil } - return try? NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) + return try? NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: true) } public func deserialize(_ object: Serializable?) -> Value? { - guard let data = object else { + guard let object else { return nil } do { - return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? Value + return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(object) as? Value } catch { print(error) return nil @@ -150,8 +135,8 @@ extension Defaults { return array.map { Element.bridge.serialize($0) }.compact() } - public func deserialize(_ object: Serializable?) -> Value? { - guard let array = object else { + public func deserialize(_ array: Serializable?) -> Value? { + guard let array else { return nil } @@ -165,8 +150,8 @@ extension Defaults { public typealias Value = [Key: Element.Value] public typealias Serializable = [String: Element.Serializable] - public func serialize(_ value: Value?) -> Serializable? { - guard let dictionary = value else { + public func serialize(_ dictionary: Value?) -> Serializable? { + guard let dictionary else { return nil } @@ -176,8 +161,8 @@ extension Defaults { } } - public func deserialize(_ object: Serializable?) -> Value? { - guard let dictionary = object else { + public func deserialize(_ dictionary: Serializable?) -> Value? { + guard let dictionary else { return nil } @@ -201,8 +186,8 @@ extension Defaults { public typealias Value = Set public typealias Serializable = Any - public func serialize(_ value: Value?) -> Serializable? { - guard let set = value else { + public func serialize(_ set: Value?) -> Serializable? { + guard let set else { return nil } @@ -240,11 +225,8 @@ extension Defaults { public typealias Element = Value.Element public typealias Serializable = Any - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - - public func serialize(_ value: Value?) -> Serializable? { - guard let setAlgebra = value else { + public func serialize(_ setAlgebra: Value?) -> Serializable? { + guard let setAlgebra else { return nil } @@ -282,11 +264,8 @@ extension Defaults { public typealias Element = Value.Element public typealias Serializable = Any - // TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. - public init() {} - - public func serialize(_ value: Value?) -> Serializable? { - guard let collection = value else { + public func serialize(_ collection: Value?) -> Serializable? { + guard let collection else { return nil } @@ -328,7 +307,7 @@ extension Defaults { } public func deserialize(_ object: Serializable?) -> Value? { - guard let object = object else { + guard let object else { return nil } @@ -344,7 +323,7 @@ extension Defaults { typealias Bound = T.Bound public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -363,7 +342,7 @@ extension Defaults { } public func deserialize(_ object: Serializable?) -> Value? { - guard let object = object else { + guard let object else { return nil } @@ -408,7 +387,7 @@ extension Defaults { #endif public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } diff --git a/Sources/Defaults/Defaults+Protocol.swift b/Sources/Defaults/Defaults+Protocol.swift index 34dde75..dbee8b0 100644 --- a/Sources/Defaults/Defaults+Protocol.swift +++ b/Sources/Defaults/Defaults+Protocol.swift @@ -57,7 +57,7 @@ struct UserBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -69,7 +69,7 @@ struct UserBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let username = object["username"], let password = object["password"] else { diff --git a/Sources/Defaults/Migration/v5/Migration+Extensions.swift b/Sources/Defaults/Migration/v5/Migration+Extensions.swift index 0b124a9..f270f1e 100644 --- a/Sources/Defaults/Migration/v5/Migration+Extensions.swift +++ b/Sources/Defaults/Migration/v5/Migration+Extensions.swift @@ -198,7 +198,7 @@ extension Defaults.SetAlgebraSerializable where Self: Defaults.NativeType, Eleme public typealias CodableForm = [Element.CodableForm] } -extension Defaults.CodableType where Self: RawRepresentable, NativeForm: RawRepresentable, RawValue == NativeForm.RawValue { +extension Defaults.CodableType where Self: RawRepresentable, NativeForm: RawRepresentable { public func toNative() -> NativeForm { NativeForm(rawValue: rawValue)! } diff --git a/Sources/Defaults/Migration/v5/Migration+Protocol.swift b/Sources/Defaults/Migration/v5/Migration+Protocol.swift index 9314338..6acf0c9 100644 --- a/Sources/Defaults/Migration/v5/Migration+Protocol.swift +++ b/Sources/Defaults/Migration/v5/Migration+Protocol.swift @@ -11,8 +11,7 @@ So we can convert the JSON string into a `NativeType` like this: ``` guard - let jsonString = string, - let jsonData = jsonString.data(using: .utf8), + let jsonData = string?.data(using: .utf8), let codable = try? JSONDecoder().decode(NativeType.CodableForm.self, from: jsonData) else { return nil diff --git a/Sources/Defaults/Migration/v5/Migration+UserDefaults.swift b/Sources/Defaults/Migration/v5/Migration+UserDefaults.swift index 3d0b21a..8738724 100644 --- a/Sources/Defaults/Migration/v5/Migration+UserDefaults.swift +++ b/Sources/Defaults/Migration/v5/Migration+UserDefaults.swift @@ -3,8 +3,7 @@ import Foundation extension UserDefaults { func migrateCodableToNative(forKey key: String, of type: Value.Type) { guard - let jsonString = string(forKey: key), - let jsonData = jsonString.data(using: .utf8), + let jsonData = string(forKey: key)?.data(using: .utf8), let codable = try? JSONDecoder().decode(Value.self, from: jsonData) else { return @@ -38,8 +37,7 @@ extension UserDefaults { */ func migrateCodableToNative(forKey key: String, of type: Value.Type) { guard - let jsonString = string(forKey: key), - let jsonData = jsonString.data(using: .utf8), + let jsonData = string(forKey: key)?.data(using: .utf8), let codable = try? JSONDecoder().decode(Value.CodableForm.self, from: jsonData) else { return diff --git a/Sources/Defaults/Observation+Combine.swift b/Sources/Defaults/Observation+Combine.swift index f2acbc1..7414a12 100644 --- a/Sources/Defaults/Observation+Combine.swift +++ b/Sources/Defaults/Observation+Combine.swift @@ -58,7 +58,7 @@ extension Defaults { self.options = options } - func receive(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input { + func receive(subscriber: some Subscriber) { let subscription = DefaultsSubscription( subscriber: subscriber, suite: suite, diff --git a/Sources/Defaults/Observation.swift b/Sources/Defaults/Observation.swift index 2d674c6..9f85a9d 100644 --- a/Sources/Defaults/Observation.swift +++ b/Sources/Defaults/Observation.swift @@ -43,7 +43,7 @@ extension Defaults { private static func deserialize(_ value: Any?, to type: Value.Type) -> Value? { guard - let value = value, + let value, !(value is NSNull) else { return nil diff --git a/Sources/Defaults/SwiftUI.swift b/Sources/Defaults/SwiftUI.swift index ff291fe..93edc54 100644 --- a/Sources/Defaults/SwiftUI.swift +++ b/Sources/Defaults/SwiftUI.swift @@ -168,7 +168,7 @@ extension Defaults { } ``` */ - public struct Toggle: View where Label: View, Key: Defaults.Key { + public struct Toggle: View { @ViewStorage private var onChange: ((Bool) -> Void)? private let label: () -> Label @@ -176,7 +176,7 @@ extension Defaults { // Intentionally using `@ObservedObjected` over `@StateObject` so that the key can be dynamically changed. @ObservedObject private var observable: Defaults.Observable - public init(key: Key, @ViewBuilder label: @escaping () -> Label) { + public init(key: Defaults.Key, @ViewBuilder label: @escaping () -> Label) { self.label = label self.observable = Defaults.Observable(key) } @@ -191,8 +191,8 @@ extension Defaults { } @available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) -extension Defaults.Toggle where Label == Text { - public init(_ title: S, key: Defaults.Key) where S: StringProtocol { +extension Defaults.Toggle { + public init(_ title: some StringProtocol, key: Defaults.Key) { self.label = { Text(title) } self.observable = Defaults.Observable(key) } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index 18c7adc..5c86555 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -104,8 +104,8 @@ final class LifetimeAssociation { private func invalidate() { guard - let owner = owner, - let wrappedObject = wrappedObject, + let owner, + let wrappedObject, var associatedObjects = Self.associatedObjects[owner], let wrappedObjectAssociationIndex = associatedObjects.firstIndex(where: { $0 === wrappedObject }) else { diff --git a/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift b/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift index c40dbd2..6188fff 100644 --- a/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift +++ b/Tests/DefaultsTests/DefaultsCollectionCustomElementTests.swift @@ -15,7 +15,7 @@ private struct ItemBridge: Defaults.Bridge { typealias Value = Item typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -24,7 +24,7 @@ private struct ItemBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let name = object["name"], let count = UInt(object["count"] ?? "0") else { diff --git a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift index 86efcaf..e8653f8 100644 --- a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift +++ b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift @@ -16,7 +16,7 @@ public final class DefaultsUserBridge: Defaults.Bridge { public typealias Serializable = [String: String] public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -25,7 +25,7 @@ public final class DefaultsUserBridge: Defaults.Bridge { public func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let username = object["username"], let password = object["password"] else { diff --git a/Tests/DefaultsTests/DefaultsMigrationTests.swift b/Tests/DefaultsTests/DefaultsMigrationTests.swift index c1dc0c9..fd602a6 100644 --- a/Tests/DefaultsTests/DefaultsMigrationTests.swift +++ b/Tests/DefaultsTests/DefaultsMigrationTests.swift @@ -52,7 +52,7 @@ private struct TimeZoneBridge: Defaults.Bridge { typealias Serializable = [String: Any] func serialize(_ value: TimeZone?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -61,9 +61,9 @@ private struct TimeZoneBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> TimeZone? { guard - let dictionary = object, - let id = dictionary["id"] as? String, - let name = dictionary["name"] as? String + let object, + let id = object["id"] as? String, + let name = object["name"] as? String else { return nil } @@ -86,7 +86,7 @@ private struct ChosenTimeZoneBridge: Defaults.Bridge { typealias Serializable = [String: Any] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -95,9 +95,9 @@ private struct ChosenTimeZoneBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let dictionary = object, - let id = dictionary["id"] as? String, - let name = dictionary["name"] as? String + let object, + let id = object["id"] as? String, + let name = object["name"] as? String else { return nil } diff --git a/Tests/DefaultsTests/DefaultsRangeTests.swift b/Tests/DefaultsTests/DefaultsRangeTests.swift index 57683c6..793175b 100644 --- a/Tests/DefaultsTests/DefaultsRangeTests.swift +++ b/Tests/DefaultsTests/DefaultsRangeTests.swift @@ -14,7 +14,7 @@ extension CustomDate: Defaults.Serializable { public typealias Serializable = [Int] public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -22,7 +22,7 @@ extension CustomDate: Defaults.Serializable { } public func deserialize(_ object: Serializable?) -> Value? { - guard let object = object else { + guard let object else { return nil } diff --git a/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift b/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift index b221f2d..fabb63c 100644 --- a/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift +++ b/Tests/DefaultsTests/DefaultsSetAlgebraCustomElementTests.swift @@ -15,7 +15,7 @@ private struct ItemBridge: Defaults.Bridge { typealias Value = Item typealias Serializable = [String: String] func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -24,7 +24,7 @@ private struct ItemBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let name = object["name"], let count = UInt(object["count"] ?? "0") else { diff --git a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift index f4b62ea..e721b83 100644 --- a/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift +++ b/Tests/DefaultsTests/DefaultsSetAlgebraTests.swift @@ -7,7 +7,7 @@ struct DefaultsSetAlgebra: SetAlgebra init() {} - init(_ sequence: __owned S) where Element == S.Element { + init(_ sequence: __owned some Sequence) { self.store = Set(sequence) } diff --git a/Tests/DefaultsTests/DefaultsTests+Workaround.swift b/Tests/DefaultsTests/DefaultsTests+Workaround.swift deleted file mode 100644 index d920a40..0000000 --- a/Tests/DefaultsTests/DefaultsTests+Workaround.swift +++ /dev/null @@ -1,38 +0,0 @@ -// TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed. -import Foundation -import Defaults - -extension Defaults.Serializable where Self: Codable { - public static var bridge: Defaults.TopLevelCodableBridge { Defaults.TopLevelCodableBridge() } -} - -extension Defaults.Serializable where Self: Codable & NSSecureCoding { - public static var bridge: Defaults.CodableNSSecureCodingBridge { Defaults.CodableNSSecureCodingBridge() } -} - -extension Defaults.Serializable where Self: Codable & NSSecureCoding & Defaults.PreferNSSecureCoding { - public static var bridge: Defaults.NSSecureCodingBridge { Defaults.NSSecureCodingBridge() } -} - -extension Defaults.Serializable where Self: Codable & RawRepresentable { - public static var bridge: Defaults.RawRepresentableCodableBridge { Defaults.RawRepresentableCodableBridge() } -} - -extension Defaults.Serializable where Self: Codable & RawRepresentable & Defaults.PreferRawRepresentable { - public static var bridge: Defaults.RawRepresentableBridge { Defaults.RawRepresentableBridge() } -} - -extension Defaults.Serializable where Self: RawRepresentable { - public static var bridge: Defaults.RawRepresentableBridge { Defaults.RawRepresentableBridge() } -} -extension Defaults.Serializable where Self: NSSecureCoding { - public static var bridge: Defaults.NSSecureCodingBridge { Defaults.NSSecureCodingBridge() } -} - -extension Defaults.CollectionSerializable where Element: Defaults.Serializable { - public static var bridge: Defaults.CollectionBridge { Defaults.CollectionBridge() } -} - -extension Defaults.SetAlgebraSerializable where Element: Defaults.Serializable & Hashable { - public static var bridge: Defaults.SetAlgebraBridge { Defaults.SetAlgebraBridge() } -} diff --git a/migration.md b/migration.md index 742ad04..d6e6945 100644 --- a/migration.md +++ b/migration.md @@ -331,7 +331,7 @@ private struct TimeZoneBridge: Defaults.Bridge { typealias Serializable = [String: String] func serialize(_ value: TimeZone?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -343,9 +343,9 @@ private struct TimeZoneBridge: Defaults.Bridge { func deserialize(_ object: Serializable?) -> TimeZone? { guard - let dictionary = object, - let id = dictionary["id"], - let name = dictionary["name"] + let object, + let id = object["id"], + let name = object["name"] else { return nil } diff --git a/readme.md b/readme.md index 5e95e1f..6c19bf0 100644 --- a/readme.md +++ b/readme.md @@ -31,7 +31,6 @@ For a real-world example, see the [Plash app](https://github.com/sindresorhus/Pl - Easy to add support for your own custom types. - Comes with a convenience SwiftUI `Toggle` component. - ## Compatibility - macOS 10.13+ @@ -39,35 +38,6 @@ For a real-world example, see the [Plash app](https://github.com/sindresorhus/Pl - tvOS 12+ - watchOS 5+ -
- ---- - - - ---- - -
- ## Migration Guides #### [From v4 to v5](./migration.md) @@ -76,7 +46,7 @@ For a real-world example, see the [Plash app](https://github.com/sindresorhus/Pl Add `https://github.com/sindresorhus/Defaults` in the [“Swift Package Manager” tab in Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app). -**There are some issues running Defaults with Xcode 13.3 because of a Swift bug. [See the workaround](workaround.md).** +**Requires Xcode 14 or later** ## Support types @@ -670,7 +640,7 @@ struct UserBridge: Defaults.Bridge { typealias Serializable = [String: String] public func serialize(_ value: Value?) -> Serializable? { - guard let value = value else { + guard let value else { return nil } @@ -682,7 +652,7 @@ struct UserBridge: Defaults.Bridge { public func deserialize(_ object: Serializable?) -> Value? { guard - let object = object, + let object, let name = object["name"], let age = object["age"] else { diff --git a/workaround.md b/workaround.md deleted file mode 100644 index c4cd80c..0000000 --- a/workaround.md +++ /dev/null @@ -1,50 +0,0 @@ -## Workaround for Xcode 13.3 - -When using `Defaults` with Xcode 13.3, the compiler may complain about `Type 'YourType' does not conform to protocol 'DefaultsSerializable'`. - -[**This is a Swift bug.**](https://bugs.swift.org/projects/SR/issues/SR-15807) - -Workaround: - -1. Create a file named `Defaults+Workaround.swift` in the project using `Defaults`. -2. Copy the below code into `Defaults+Workaround.swift`. - -```swift -import Foundation -import Defaults - -extension Defaults.Serializable where Self: Codable { - public static var bridge: Defaults.TopLevelCodableBridge { Defaults.TopLevelCodableBridge() } -} - -extension Defaults.Serializable where Self: Codable & NSSecureCoding { - public static var bridge: Defaults.CodableNSSecureCodingBridge { Defaults.CodableNSSecureCodingBridge() } -} - -extension Defaults.Serializable where Self: Codable & NSSecureCoding & Defaults.PreferNSSecureCoding { - public static var bridge: Defaults.NSSecureCodingBridge { Defaults.NSSecureCodingBridge() } -} - -extension Defaults.Serializable where Self: Codable & RawRepresentable { - public static var bridge: Defaults.RawRepresentableCodableBridge { Defaults.RawRepresentableCodableBridge() } -} - -extension Defaults.Serializable where Self: Codable & RawRepresentable & Defaults.PreferRawRepresentable { - public static var bridge: Defaults.RawRepresentableBridge { Defaults.RawRepresentableBridge() } -} - -extension Defaults.Serializable where Self: RawRepresentable { - public static var bridge: Defaults.RawRepresentableBridge { Defaults.RawRepresentableBridge() } -} -extension Defaults.Serializable where Self: NSSecureCoding { - public static var bridge: Defaults.NSSecureCodingBridge { Defaults.NSSecureCodingBridge() } -} - -extension Defaults.CollectionSerializable where Element: Defaults.Serializable { - public static var bridge: Defaults.CollectionBridge { Defaults.CollectionBridge() } -} - -extension Defaults.SetAlgebraSerializable where Element: Defaults.Serializable & Hashable { - public static var bridge: Defaults.SetAlgebraBridge { Defaults.SetAlgebraBridge() } -} -```