@@ -35,21 +35,21 @@ extension Defaults.CodableBridge {
3535Any `Value` that conforms to `Codable` and `Defaults.Serializable` will use `CodableBridge` to do the serialization and deserialization.
3636*/
3737extension Defaults {
38- public struct TopLevelCodableBridge < Value: Codable > : CodableBridge { }
38+ public struct TopLevelCodableBridge < Value: Codable > : CodableBridge , Sendable { }
3939}
4040
4141/**
4242`RawRepresentableCodableBridge` is needed because, for example, with `enum SomeEnum: String, Codable, Defaults.Serializable`, the compiler will be confused between `RawRepresentableBridge` and `TopLevelCodableBridge`.
4343*/
4444extension Defaults {
45- public struct RawRepresentableCodableBridge < Value: RawRepresentable & Codable > : CodableBridge { }
45+ public struct RawRepresentableCodableBridge < Value: RawRepresentable & Codable > : CodableBridge , Sendable { }
4646}
4747
4848/**
4949This exists to avoid compiler ambiguity.
5050*/
5151extension Defaults {
52- public struct CodableNSSecureCodingBridge < Value: Codable & NSSecureCoding & NSObject > : CodableBridge { }
52+ public struct CodableNSSecureCodingBridge < Value: Codable & NSSecureCoding & NSObject > : CodableBridge , Sendable { }
5353}
5454
5555extension Defaults {
@@ -59,7 +59,7 @@ extension Defaults {
5959}
6060
6161extension Defaults {
62- public struct RawRepresentableBridge < Value: RawRepresentable > : Bridge {
62+ public struct RawRepresentableBridge < Value: RawRepresentable > : Bridge , Sendable {
6363 public typealias Serializable = Value . RawValue
6464
6565 public func serialize( _ value: Value ? ) -> Serializable ? {
@@ -77,7 +77,7 @@ extension Defaults {
7777}
7878
7979extension Defaults {
80- public struct NSSecureCodingBridge < Value: NSSecureCoding & NSObject > : Bridge {
80+ public struct NSSecureCodingBridge < Value: NSSecureCoding & NSObject > : Bridge , Sendable {
8181 public typealias Serializable = Data
8282
8383 public func serialize( _ value: Value ? ) -> Serializable ? {
@@ -104,7 +104,7 @@ extension Defaults {
104104}
105105
106106extension Defaults {
107- public struct OptionalBridge < Wrapped: Serializable > : Bridge {
107+ public struct OptionalBridge < Wrapped: Serializable > : Bridge , Sendable {
108108 public typealias Value = Wrapped . Value
109109 public typealias Serializable = Wrapped . Serializable
110110
@@ -119,7 +119,7 @@ extension Defaults {
119119}
120120
121121extension Defaults {
122- public struct ArrayBridge < Element: Serializable > : Bridge {
122+ public struct ArrayBridge < Element: Serializable > : Bridge , Sendable {
123123 public typealias Value = [ Element ]
124124 public typealias Serializable = [ Element . Serializable ]
125125
@@ -142,7 +142,7 @@ extension Defaults {
142142}
143143
144144extension Defaults {
145- public struct DictionaryBridge < Key: LosslessStringConvertible & Hashable , Element: Serializable > : Bridge {
145+ public struct DictionaryBridge < Key: LosslessStringConvertible & Hashable , Element: Serializable > : Bridge , Sendable {
146146 public typealias Value = [ Key : Element . Value ]
147147 public typealias Serializable = [ String : Element . Serializable ]
148148
@@ -178,7 +178,7 @@ extension Defaults {
178178We need both `SetBridge` and `SetAlgebraBridge` because `Set` conforms to `Sequence` but `SetAlgebra` does not. `Set` conforms to `Sequence`, so we can convert it into an array with `Array.init<S>(S)` and store it in the `UserDefaults`. But `SetAlgebra` does not, so it is hard to convert it into an array. Thats why we need the `Defaults.SetAlgebraSerializable` protocol to convert it into an array.
179179*/
180180extension Defaults {
181- public struct SetBridge < Element: Serializable & Hashable > : Bridge {
181+ public struct SetBridge < Element: Serializable & Hashable > : Bridge , Sendable {
182182 public typealias Value = Set < Element >
183183 public typealias Serializable = Any
184184
@@ -187,11 +187,11 @@ extension Defaults {
187187 return nil
188188 }
189189
190- if Element . isNativelySupportedType {
191- return Array ( set)
190+ return if Element . isNativelySupportedType {
191+ Array ( set)
192+ } else {
193+ set. map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
192194 }
193-
194- return set. map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
195195 }
196196
197197 public func deserialize( _ object: Serializable ? ) -> Value ? {
@@ -216,7 +216,7 @@ extension Defaults {
216216}
217217
218218extension Defaults {
219- public struct SetAlgebraBridge < Value: SetAlgebraSerializable > : Bridge where Value. Element: Serializable {
219+ public struct SetAlgebraBridge < Value: SetAlgebraSerializable > : Bridge , Sendable where Value. Element: Serializable {
220220 public typealias Element = Value . Element
221221 public typealias Serializable = Any
222222
@@ -225,11 +225,11 @@ extension Defaults {
225225 return nil
226226 }
227227
228- if Element . isNativelySupportedType {
229- return setAlgebra. toArray ( )
228+ return if Element . isNativelySupportedType {
229+ setAlgebra. toArray ( )
230+ } else {
231+ setAlgebra. toArray ( ) . map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
230232 }
231-
232- return setAlgebra. toArray ( ) . map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
233233 }
234234
235235 public func deserialize( _ object: Serializable ? ) -> Value ? {
@@ -254,7 +254,7 @@ extension Defaults {
254254}
255255
256256extension Defaults {
257- public struct CollectionBridge < Value: CollectionSerializable > : Bridge where Value. Element: Serializable {
257+ public struct CollectionBridge < Value: CollectionSerializable > : Bridge , Sendable where Value. Element: Serializable {
258258 public typealias Element = Value . Element
259259 public typealias Serializable = Any
260260
@@ -263,11 +263,11 @@ extension Defaults {
263263 return nil
264264 }
265265
266- if Element . isNativelySupportedType {
267- return Array ( collection)
266+ return if Element . isNativelySupportedType {
267+ Array ( collection)
268+ } else {
269+ collection. map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
268270 }
269-
270- return collection. map { Element . bridge. serialize ( $0 as? Element . Value ) } . compact ( )
271271 }
272272
273273 public func deserialize( _ object: Serializable ? ) -> Value ? {
@@ -311,7 +311,7 @@ extension Defaults {
311311}
312312
313313extension Defaults {
314- public struct RangeBridge < T: RangeSerializable > : Bridge {
314+ public struct RangeBridge < T: RangeSerializable > : Bridge , Sendable {
315315 public typealias Value = T
316316 public typealias Serializable = [ Any ]
317317 typealias Bound = T . Bound
@@ -323,16 +323,16 @@ extension Defaults {
323323
324324 if Bound . isNativelySupportedType {
325325 return [ value. lowerBound, value. upperBound]
326- }
326+ } else {
327+ guard
328+ let lowerBound = Bound . bridge. serialize ( value. lowerBound as? Bound . Value ) ,
329+ let upperBound = Bound . bridge. serialize ( value. upperBound as? Bound . Value )
330+ else {
331+ return nil
332+ }
327333
328- guard
329- let lowerBound = Bound . bridge. serialize ( value. lowerBound as? Bound . Value ) ,
330- let upperBound = Bound . bridge. serialize ( value. upperBound as? Bound . Value )
331- else {
332- return nil
334+ return [ lowerBound, upperBound]
333335 }
334-
335- return [ lowerBound, upperBound]
336336 }
337337
338338 public func deserialize( _ object: Serializable ? ) -> Value ? {
0 commit comments