Skip to content

Commit 9aa2b75

Browse files
committed
Move all docs to DocC
1 parent 8192b09 commit 9aa2b75

File tree

11 files changed

+1075
-821
lines changed

11 files changed

+1075
-821
lines changed

Package.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.11
1+
// swift-tools-version:6.2
22
import PackageDescription
33
import CompilerPluginSupport
44

@@ -33,10 +33,10 @@ let package = Package(
3333
name: "Defaults",
3434
resources: [
3535
.copy("PrivacyInfo.xcprivacy")
36+
],
37+
swiftSettings: [
38+
.swiftLanguageMode(.v5)
3639
]
37-
// swiftSettings: [
38-
// .swiftLanguageMode(.v5)
39-
// ]
4040
),
4141
.macro(
4242
name: "DefaultsMacrosDeclarations",
@@ -54,10 +54,10 @@ let package = Package(
5454
name: "DefaultsTests",
5555
dependencies: [
5656
"Defaults"
57+
],
58+
swiftSettings: [
59+
.swiftLanguageMode(.v5)
5760
]
58-
// swiftSettings: [
59-
// .swiftLanguageMode(.v5)
60-
// ]
6161
),
6262
.testTarget(
6363
name: "DefaultsMacrosDeclarationsTests",

Sources/Defaults/Defaults+Bridge.swift

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ extension Defaults.CodableBridge {
3535
Any `Value` that conforms to `Codable` and `Defaults.Serializable` will use `CodableBridge` to do the serialization and deserialization.
3636
*/
3737
extension 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
*/
4444
extension Defaults {
45-
public struct RawRepresentableCodableBridge<Value: RawRepresentable & Codable>: CodableBridge {}
45+
public struct RawRepresentableCodableBridge<Value: RawRepresentable & Codable>: CodableBridge, Sendable {}
4646
}
4747

4848
/**
4949
This exists to avoid compiler ambiguity.
5050
*/
5151
extension Defaults {
52-
public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding & NSObject>: CodableBridge {}
52+
public struct CodableNSSecureCodingBridge<Value: Codable & NSSecureCoding & NSObject>: CodableBridge, Sendable {}
5353
}
5454

5555
extension Defaults {
@@ -59,7 +59,7 @@ extension Defaults {
5959
}
6060

6161
extension 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

7979
extension 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

106106
extension 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

121121
extension 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

144144
extension 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 {
178178
We 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
*/
180180
extension 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

218218
extension 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

256256
extension 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

313313
extension 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? {

Sources/Defaults/Defaults+Protocol.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension Defaults {
1717
}
1818
```
1919
*/
20-
public protocol Serializable {
20+
public protocol Serializable<Bridge> {
2121
typealias Value = Bridge.Value
2222
typealias Serializable = Bridge.Serializable
2323
associatedtype Bridge: Defaults.Bridge
@@ -35,7 +35,7 @@ extension Defaults {
3535
}
3636

3737
extension Defaults {
38-
public protocol Bridge {
38+
public protocol Bridge<Value, Serializable> {
3939
associatedtype Value
4040
associatedtype Serializable
4141

@@ -67,14 +67,14 @@ extension Defaults {
6767
}
6868

6969
extension Defaults {
70-
public protocol CollectionSerializable: Collection, Serializable {
70+
public protocol CollectionSerializable<Element>: Collection, Serializable {
7171
/**
7272
`Collection` does not have a initializer, but we need a initializer to convert an array into the `Value`.
7373
*/
7474
init(_ elements: [Element])
7575
}
7676

77-
public protocol SetAlgebraSerializable: SetAlgebra, Serializable {
77+
public protocol SetAlgebraSerializable<Element>: SetAlgebra, Serializable {
7878
/**
7979
Since `SetAlgebra` protocol does not conform to `Sequence`, we cannot convert a `SetAlgebra` to an `Array` directly.
8080
*/
@@ -84,7 +84,7 @@ extension Defaults {
8484
public protocol CodableBridge: Bridge where Serializable == String, Value: Codable {}
8585

8686
// Essential properties for serializing and deserializing `ClosedRange` and `Range`.
87-
public protocol Range {
87+
public protocol Range<Bound> {
8888
associatedtype Bound: Comparable, Defaults.Serializable
8989

9090
var lowerBound: Bound { get }

0 commit comments

Comments
 (0)