Skip to content

Commit d5e4ef5

Browse files
Added support for Swift 6
1 parent 609e9e0 commit d5e4ef5

File tree

6 files changed

+96
-7
lines changed

6 files changed

+96
-7
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
),
1919
],
2020
dependencies: [
21-
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.2.1")),
21+
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")),
2222
.package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")),
2323
],
2424
targets: [
@@ -29,14 +29,14 @@ let package = Package(
2929
"Bytes"
3030
],
3131
swiftSettings: [
32-
.enableExperimentalFeature("StrictConcurrency")
32+
.enableExperimentalFeature("StrictConcurrency"),
3333
]
3434
),
3535
.testTarget(
3636
name: "CodableDatastoreTests",
3737
dependencies: ["CodableDatastore"],
3838
swiftSettings: [
39-
.enableExperimentalFeature("StrictConcurrency")
39+
.enableExperimentalFeature("StrictConcurrency"),
4040
]
4141
),
4242
]

Package@swift-6.0.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "CodableDatastore",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
.watchOS(.v6),
13+
],
14+
products: [
15+
.library(
16+
name: "CodableDatastore",
17+
targets: ["CodableDatastore"]
18+
),
19+
],
20+
dependencies: [
21+
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")),
22+
.package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")),
23+
],
24+
targets: [
25+
.target(
26+
name: "CodableDatastore",
27+
dependencies: [
28+
"AsyncSequenceReader",
29+
"Bytes"
30+
],
31+
swiftSettings: [
32+
.swiftLanguageVersion(.v6),
33+
]
34+
),
35+
.testTarget(
36+
name: "CodableDatastoreTests",
37+
dependencies: ["CodableDatastore"],
38+
swiftSettings: [
39+
.swiftLanguageVersion(.v6),
40+
]
41+
),
42+
]
43+
)

Sources/CodableDatastore/Indexes/IndexRepresentation.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,8 @@ public struct AnyIndexRepresentation<Instance: Sendable>: Hashable, Sendable {
276276
}
277277

278278
/// Forced KeyPath conformance since Swift 5.10 doesn't support it out of the box.
279+
#if compiler(>=6)
280+
extension KeyPath: @unchecked @retroactive Sendable where Root: Sendable, Value: Sendable {}
281+
#else
279282
extension KeyPath: @unchecked Sendable where Root: Sendable, Value: Sendable {}
283+
#endif

Sources/CodableDatastore/Indexes/Indexable.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,21 @@ extension UInt16: DiscreteIndexable, RangedIndexable {}
7777
extension UInt32: DiscreteIndexable, RangedIndexable {}
7878
extension UInt64: DiscreteIndexable, RangedIndexable {}
7979

80+
#if compiler(>=6)
81+
extension Optional: @retroactive Comparable where Wrapped: Comparable {
82+
public static func < (lhs: Self, rhs: Self) -> Bool {
83+
if let lhs, let rhs { return lhs < rhs }
84+
return lhs == nil && rhs != nil
85+
}
86+
}
87+
#else
8088
extension Optional: Comparable where Wrapped: Comparable {
8189
public static func < (lhs: Self, rhs: Self) -> Bool {
8290
if let lhs, let rhs { return lhs < rhs }
8391
return lhs == nil && rhs != nil
8492
}
8593
}
94+
#endif
8695
extension Optional: DiscreteIndexable where Wrapped: DiscreteIndexable {}
8796
extension Optional: RangedIndexable where Wrapped: RangedIndexable {}
8897

Sources/CodableDatastore/Indexes/UUID+Comparable.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@ import Foundation
1010

1111
#if swift(<5.9) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(Windows)
1212
/// Make UUIDs comparable, so that they can be used transparently as an index.
13-
///
14-
/// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156
13+
#if compiler(>=6)
14+
extension UUID: @retroactive Comparable {
15+
@inlinable
16+
public static func < (lhs: UUID, rhs: UUID) -> Bool {
17+
lhs.isLessThan(rhs: rhs)
18+
}
19+
}
20+
#else
1521
extension UUID: Comparable {
1622
@inlinable
1723
public static func < (lhs: UUID, rhs: UUID) -> Bool {
18-
var leftUUID = lhs.uuid
24+
lhs.isLessThan(rhs: rhs)
25+
}
26+
}
27+
#endif
28+
#endif
29+
30+
extension UUID {
31+
/// Make UUIDs comparable, so that they can be used transparently as an index.
32+
///
33+
/// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156
34+
@usableFromInline
35+
func isLessThan(rhs: UUID) -> Bool {
36+
var leftUUID = self.uuid
1937
var rightUUID = rhs.uuid
2038
var result: Int = 0
2139
var diff: Int = 0
@@ -36,4 +54,3 @@ extension UUID: Comparable {
3654
return result < 0
3755
}
3856
}
39-
#endif

Sources/CodableDatastore/Persistence/Disk Persistence/ISO8601DateFormatter+Milliseconds.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import Foundation
1010

1111
extension ISO8601DateFormatter {
12+
#if compiler(>=6)
13+
nonisolated(unsafe)
1214
static let withMilliseconds: ISO8601DateFormatter = {
1315
let formatter = ISO8601DateFormatter()
1416
formatter.timeZone = TimeZone(secondsFromGMT: 0)
@@ -21,6 +23,20 @@ extension ISO8601DateFormatter {
2123
]
2224
return formatter
2325
}()
26+
#else
27+
static let withMilliseconds: ISO8601DateFormatter = {
28+
let formatter = ISO8601DateFormatter()
29+
formatter.timeZone = TimeZone(secondsFromGMT: 0)
30+
formatter.formatOptions = [
31+
.withInternetDateTime,
32+
.withDashSeparatorInDate,
33+
.withColonSeparatorInTime,
34+
.withTimeZone,
35+
.withFractionalSeconds
36+
]
37+
return formatter
38+
}()
39+
#endif
2440
}
2541

2642
extension JSONDecoder.DateDecodingStrategy {

0 commit comments

Comments
 (0)