From 57291b620e54dad080977ad7e8cd701fede32e57 Mon Sep 17 00:00:00 2001 From: Nikolay Morev Date: Thu, 6 Jul 2023 13:23:01 +0300 Subject: [PATCH 1/2] Add Sendable conformance --- Sources/AnyCodable/AnyCodable.swift | 2 +- Sources/AnyCodable/AnyDecodable.swift | 2 +- Sources/AnyCodable/AnyEncodable.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/AnyCodable/AnyCodable.swift b/Sources/AnyCodable/AnyCodable.swift index 5f9924d..1942923 100644 --- a/Sources/AnyCodable/AnyCodable.swift +++ b/Sources/AnyCodable/AnyCodable.swift @@ -12,7 +12,7 @@ import Foundation - SeeAlso: `AnyEncodable` - SeeAlso: `AnyDecodable` */ -@frozen public struct AnyCodable: Codable { +@frozen public struct AnyCodable: Codable, @unchecked Sendable { public let value: Any public init(_ value: T?) { diff --git a/Sources/AnyCodable/AnyDecodable.swift b/Sources/AnyCodable/AnyDecodable.swift index 9b42228..48a2ccb 100644 --- a/Sources/AnyCodable/AnyDecodable.swift +++ b/Sources/AnyCodable/AnyDecodable.swift @@ -31,7 +31,7 @@ import Foundation let decoder = JSONDecoder() let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json) */ -@frozen public struct AnyDecodable: Decodable { +@frozen public struct AnyDecodable: Decodable, @unchecked Sendable { public let value: Any public init(_ value: T?) { diff --git a/Sources/AnyCodable/AnyEncodable.swift b/Sources/AnyCodable/AnyEncodable.swift index d5530e5..8de9edc 100644 --- a/Sources/AnyCodable/AnyEncodable.swift +++ b/Sources/AnyCodable/AnyEncodable.swift @@ -29,7 +29,7 @@ import Foundation let encoder = JSONEncoder() let json = try! encoder.encode(dictionary) */ -@frozen public struct AnyEncodable: Encodable { +@frozen public struct AnyEncodable: Encodable, @unchecked Sendable { public let value: Any public init(_ value: T?) { From a457aa6962bd790eeafd65be9d37f62d2c15a71a Mon Sep 17 00:00:00 2001 From: Nikolay Morev Date: Mon, 7 Aug 2023 13:20:06 +0300 Subject: [PATCH 2/2] Fix for old Swift versions --- Sources/AnyCodable/AnyCodable.swift | 12 +++++++++++- Sources/AnyCodable/AnyDecodable.swift | 12 +++++++++++- Sources/AnyCodable/AnyEncodable.swift | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Sources/AnyCodable/AnyCodable.swift b/Sources/AnyCodable/AnyCodable.swift index 1942923..6565855 100644 --- a/Sources/AnyCodable/AnyCodable.swift +++ b/Sources/AnyCodable/AnyCodable.swift @@ -12,13 +12,23 @@ import Foundation - SeeAlso: `AnyEncodable` - SeeAlso: `AnyDecodable` */ -@frozen public struct AnyCodable: Codable, @unchecked Sendable { +#if compiler(>=5.6) +@preconcurrency @frozen public struct AnyCodable: Codable, @unchecked Sendable { public let value: Any public init(_ value: T?) { self.value = value ?? () } } +#else +@frozen public struct AnyCodable: Codable { + public let value: Any + + public init(_ value: T?) { + self.value = value ?? () + } +} +#endif extension AnyCodable: _AnyEncodable, _AnyDecodable {} diff --git a/Sources/AnyCodable/AnyDecodable.swift b/Sources/AnyCodable/AnyDecodable.swift index 48a2ccb..c1cdd19 100644 --- a/Sources/AnyCodable/AnyDecodable.swift +++ b/Sources/AnyCodable/AnyDecodable.swift @@ -31,13 +31,23 @@ import Foundation let decoder = JSONDecoder() let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json) */ -@frozen public struct AnyDecodable: Decodable, @unchecked Sendable { +#if compiler(>=5.6) +@preconcurrency @frozen public struct AnyDecodable: Decodable, @unchecked Sendable { public let value: Any public init(_ value: T?) { self.value = value ?? () } } +#else +@frozen public struct AnyDecodable: Decodable { + public let value: Any + + public init(_ value: T?) { + self.value = value ?? () + } +} +#endif @usableFromInline protocol _AnyDecodable { diff --git a/Sources/AnyCodable/AnyEncodable.swift b/Sources/AnyCodable/AnyEncodable.swift index 8de9edc..c6ce0c6 100644 --- a/Sources/AnyCodable/AnyEncodable.swift +++ b/Sources/AnyCodable/AnyEncodable.swift @@ -29,13 +29,23 @@ import Foundation let encoder = JSONEncoder() let json = try! encoder.encode(dictionary) */ -@frozen public struct AnyEncodable: Encodable, @unchecked Sendable { +#if compiler(>=5.6) +@preconcurrency @frozen public struct AnyEncodable: Encodable, @unchecked Sendable { public let value: Any public init(_ value: T?) { self.value = value ?? () } } +#else +@frozen public struct AnyEncodable: Encodable { + public let value: Any + + public init(_ value: T?) { + self.value = value ?? () + } +} +#endif @usableFromInline protocol _AnyEncodable {