Skip to content

Commit d96a272

Browse files
authored
Adding Support for Swift 6 (#292)
Adding Support for Swift 6 (#1)
1 parent efda1cc commit d96a272

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

Sources/XMLCoder/Auxiliaries/Box/DateBox.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
struct DateBox: Equatable {
11+
struct DateBox: Equatable, Sendable {
1212
enum Format: Equatable {
1313
case secondsSince1970
1414
case millisecondsSince1970
@@ -44,7 +44,7 @@ struct DateBox: Equatable {
4444

4545
init?(iso8601 string: String) {
4646
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
47-
guard let unboxed = _iso8601Formatter.date(from: string) else {
47+
guard let unboxed = ISO8601DateFormatter.xmlCoderFormatter().date(from: string) else {
4848
return nil
4949
}
5050
self.init(unboxed, format: .iso8601)
@@ -70,7 +70,7 @@ struct DateBox: Equatable {
7070
return milliseconds.description
7171
case .iso8601:
7272
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
73-
return _iso8601Formatter.string(from: self.unboxed)
73+
return ISO8601DateFormatter.xmlCoderFormatter().string(from: self.unboxed)
7474
} else {
7575
fatalError("ISO8601DateFormatter is unavailable on this platform.")
7676
}

Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
import Foundation
1010

11-
/// Shared ISO8601 Date Formatter
12-
/// NOTE: This value is implicitly lazy and _must_ be lazy. We're compiled
13-
/// against the latest SDK (w/ ISO8601DateFormatter), but linked against
14-
/// whichever Foundation the user has. ISO8601DateFormatter might not exist, so
15-
/// we better not hit this code path on an older OS.
16-
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
17-
var _iso8601Formatter: ISO8601DateFormatter = {
18-
let formatter = ISO8601DateFormatter()
19-
formatter.formatOptions = .withInternetDateTime
20-
return formatter
21-
}()
11+
extension ISO8601DateFormatter {
12+
static func xmlCoderFormatter() -> ISO8601DateFormatter {
13+
let formatter = ISO8601DateFormatter()
14+
formatter.formatOptions = .withInternetDateTime
15+
return formatter
16+
}
17+
}

Sources/XMLCoder/Encoder/DynamicNodeEncoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</book>
4141
```
4242
*/
43-
public protocol DynamicNodeEncoding: Encodable {
43+
public protocol DynamicNodeEncoding: Encodable, Sendable {
4444
static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding
4545
}
4646

Sources/XMLCoder/Encoder/XMLEncoder.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open class XMLEncoder {
1313
// MARK: Options
1414

1515
/// The formatting of the output XML data.
16-
public struct OutputFormatting: OptionSet {
16+
public struct OutputFormatting: OptionSet, Sendable {
1717
/// The format's default value.
1818
public let rawValue: UInt
1919

@@ -39,7 +39,7 @@ open class XMLEncoder {
3939
}
4040

4141
/// A node's encoding type. Specifies how a node will be encoded.
42-
public enum NodeEncoding {
42+
public enum NodeEncoding : Sendable {
4343
case attribute
4444
case element
4545
case both
@@ -233,8 +233,8 @@ open class XMLEncoder {
233233
@available(*, deprecated, renamed: "NodeEncodingStrategy")
234234
public typealias NodeEncodingStrategies = NodeEncodingStrategy
235235

236-
public typealias XMLNodeEncoderClosure = (CodingKey) -> NodeEncoding?
237-
public typealias XMLEncodingClosure = (Encodable.Type, Encoder) -> XMLNodeEncoderClosure
236+
public typealias XMLNodeEncoderClosure = @Sendable (CodingKey) -> NodeEncoding?
237+
public typealias XMLEncodingClosure = @Sendable (Encodable.Type, Encoder) -> XMLNodeEncoderClosure
238238

239239
/// Set of strategies to use for encoding of nodes.
240240
public enum NodeEncodingStrategy {
@@ -262,7 +262,13 @@ open class XMLEncoder {
262262
guard let dynamicType = codableType as? DynamicNodeEncoding.Type else {
263263
return { _ in nil }
264264
}
265-
return dynamicType.nodeEncoding(for:)
265+
#if compiler(>=6.1)
266+
return dynamicType.nodeEncoding(for:)
267+
#else
268+
return { (@Sendable key: CodingKey) in
269+
dynamicType.nodeEncoding(for: key)
270+
}
271+
#endif
266272
}
267273
}
268274

0 commit comments

Comments
 (0)