diff --git a/Sources/AnyCodable/AnyCodable.swift b/Sources/AnyCodable/AnyCodable.swift index 5f9924d..6565855 100644 --- a/Sources/AnyCodable/AnyCodable.swift +++ b/Sources/AnyCodable/AnyCodable.swift @@ -12,6 +12,15 @@ import Foundation - SeeAlso: `AnyEncodable` - SeeAlso: `AnyDecodable` */ +#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 @@ -19,6 +28,7 @@ import Foundation self.value = value ?? () } } +#endif extension AnyCodable: _AnyEncodable, _AnyDecodable {} diff --git a/Sources/AnyCodable/AnyDecodable.swift b/Sources/AnyCodable/AnyDecodable.swift index 9b42228..c1cdd19 100644 --- a/Sources/AnyCodable/AnyDecodable.swift +++ b/Sources/AnyCodable/AnyDecodable.swift @@ -31,6 +31,15 @@ import Foundation let decoder = JSONDecoder() let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json) */ +#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 @@ -38,6 +47,7 @@ import Foundation self.value = value ?? () } } +#endif @usableFromInline protocol _AnyDecodable { diff --git a/Sources/AnyCodable/AnyEncodable.swift b/Sources/AnyCodable/AnyEncodable.swift index d5530e5..c6ce0c6 100644 --- a/Sources/AnyCodable/AnyEncodable.swift +++ b/Sources/AnyCodable/AnyEncodable.swift @@ -29,6 +29,15 @@ import Foundation let encoder = JSONEncoder() let json = try! encoder.encode(dictionary) */ +#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 @@ -36,6 +45,7 @@ import Foundation self.value = value ?? () } } +#endif @usableFromInline protocol _AnyEncodable {