Skip to content

Support swift 6 #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
24 changes: 8 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
// swift-tools-version:5.1
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

#if swift(>=5.9)
let platforms: [PackageDescription.SupportedPlatform] = [.macOS(.v10_13), .iOS(.v12), .watchOS(.v4), .tvOS(.v12)]
#elseif swift(>=5.7)
let platforms: [PackageDescription.SupportedPlatform] = [.macOS(.v10_13), .iOS(.v11), .watchOS(.v4), .tvOS(.v11)]
#elseif swift(>=5.0)
let platforms: [PackageDescription.SupportedPlatform]? = nil
#endif

let package = Package(
name: "XMLCoder",
platforms: platforms,
platforms: [
.macOS(.v12),
.iOS(.v15),
.watchOS(.v8),
.tvOS(.v15)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "XMLCoder",
targets: ["XMLCoder"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "XMLCoder",
dependencies: []
name: "XMLCoder"
),
.testTarget(
name: "XMLCoderTests",
Expand Down
1 change: 1 addition & 0 deletions Sources/XMLCoder/Auxiliaries/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extension Attribute: Codable where Value: Codable {

extension Attribute: Equatable where Value: Equatable {}
extension Attribute: Hashable where Value: Hashable {}
extension Attribute: Sendable where Value: Sendable {}

extension Attribute: ExpressibleByIntegerLiteral where Value: ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Value.IntegerLiteralType
Expand Down
16 changes: 4 additions & 12 deletions Sources/XMLCoder/Auxiliaries/Box/DateBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ struct DateBox: Equatable {
}

init?(iso8601 string: String) {
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
guard let unboxed = _iso8601Formatter.date(from: string) else {
return nil
}
self.init(unboxed, format: .iso8601)
} else {
fatalError("ISO8601DateFormatter is unavailable on this platform.")
guard let unboxed = try? Date(string, strategy: .iso8601) else {
return nil
}
self.init(unboxed, format: .iso8601)
}

init?(xmlString: String, formatter: DateFormatter) {
Expand All @@ -69,11 +65,7 @@ struct DateBox: Equatable {
let milliseconds = unboxed.timeIntervalSince1970 * 1000.0
return milliseconds.description
case .iso8601:
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
return _iso8601Formatter.string(from: self.unboxed)
} else {
fatalError("ISO8601DateFormatter is unavailable on this platform.")
}
return Date.ISO8601FormatStyle().format(self.unboxed)
case let .formatter(formatter):
return formatter.string(from: unboxed)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/XMLCoder/Auxiliaries/Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ extension Element: Codable where Value: Codable {

extension Element: Equatable where Value: Equatable {}
extension Element: Hashable where Value: Hashable {}
extension Element: Sendable where Value: Sendable {}
1 change: 1 addition & 0 deletions Sources/XMLCoder/Auxiliaries/ElementAndAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ extension ElementAndAttribute: Codable where Value: Codable {

extension ElementAndAttribute: Equatable where Value: Equatable {}
extension ElementAndAttribute: Hashable where Value: Hashable {}
extension ElementAndAttribute: Sendable where Value: Sendable {}
21 changes: 0 additions & 21 deletions Sources/XMLCoder/Auxiliaries/ISO8601DateFormatter.swift

This file was deleted.

1 change: 0 additions & 1 deletion Sources/XMLCoder/Decoder/XMLDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ open class XMLDecoder {
case millisecondsSince1970

/// Decode the `Date` as an ISO-8601-formatted string (in RFC 3339 format).
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
case iso8601

/// Decode the `Date` as a string parsed by the given formatter.
Expand Down
7 changes: 3 additions & 4 deletions Sources/XMLCoder/Encoder/XMLEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open class XMLEncoder {
// MARK: Options

/// The formatting of the output XML data.
public struct OutputFormatting: OptionSet {
public struct OutputFormatting: OptionSet, Sendable {
/// The format's default value.
public let rawValue: UInt

Expand All @@ -39,7 +39,7 @@ open class XMLEncoder {
}

/// A node's encoding type. Specifies how a node will be encoded.
public enum NodeEncoding {
public enum NodeEncoding: Sendable {
case attribute
case element
case both
Expand All @@ -59,7 +59,6 @@ open class XMLEncoder {
case millisecondsSince1970

/// Encode the `Date` as an ISO-8601-formatted string (in RFC 3339 format).
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
case iso8601

/// Encode the `Date` as a string formatted by the given formatter.
Expand Down Expand Up @@ -234,7 +233,7 @@ open class XMLEncoder {
public typealias NodeEncodingStrategies = NodeEncodingStrategy

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

/// Set of strategies to use for encoding of nodes.
public enum NodeEncodingStrategy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import XCTest
import XMLCoder

private struct Book: Codable, Equatable {
private struct Book: Codable, Equatable, Sendable {
@Attribute var id: Int
@Element var name: String
@ElementAndAttribute var authorID: Int
Expand Down
1 change: 0 additions & 1 deletion Tests/XMLCoderTests/CombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ final class CustomEncoder: XMLEncoder {
}
}

@available(iOS 13.0, macOS 10.15.0, tvOS 13.0, watchOS 6.0, *)
final class CombineTests: XCTestCase {
func testDecode() {
var foo: Foo?
Expand Down