Summary
DictionaryEncoder and DictionaryDecoder are currently open class. They should be converted to public struct and made Sendable.
Proposed Changes
struct + Sendable
open class DictionaryEncoder → public struct DictionaryEncoder: Sendable
open class DictionaryDecoder → public struct DictionaryDecoder: Sendable
open var properties → public var
userInfo
userInfo: [CodingUserInfoKey: Any] → userInfo: [CodingUserInfoKey: any Sendable] on both types
- Update
DictionaryEncoderOptions and DictionaryDecoderOptions to match
- Bridge
[CodingUserInfoKey: any Sendable] → [CodingUserInfoKey: Any] in DictionaryEncoderImpl/DictionaryDecoderImpl to satisfy the Encoder/Decoder protocol requirement
Remove DateEncodingStrategy / DateDecodingStrategy
Unlike JSON, [String: Any] can hold a Date value natively — no serialization to string or number is needed. The strategies .secondsSince1970, .millisecondsSince1970, .iso8601, and .formatted(DateFormatter) only make sense for formats that cannot represent Date directly. For a dictionary, .deferredToDate is the only meaningful strategy, so the entire DateEncodingStrategy/DateDecodingStrategy enums can be removed. This also eliminates the DateFormatter / Sendable problem entirely and allows the struct to conform to Sendable without @unchecked.
Other Sendable fixes
MissingValueDecodingStrategy.useDefault(defaults: [String: Any]) → [String: any Sendable]
- Add
@Sendable to all closure-typed enum cases (DataEncodingStrategy.custom, KeyEncodingStrategy.custom, DataDecodingStrategy.custom, KeyDecodingStrategy.custom)
Files to Update
Sources/DictionaryCoding/DictionaryEncoder.swift
Sources/DictionaryCoding/DictionaryDecoder.swift
Sources/DictionaryCoding/DictionaryEncoderOptions.swift
Sources/DictionaryCoding/DictionaryDecoderOptions.swift
Sources/DictionaryCoding/DictionaryEncoderImpl.swift
Sources/DictionaryCoding/DictionaryDecoderImpl.swift
Sources/DictionaryCoding/DictionaryEncoderImpl+Box.swift
Sources/DictionaryCoding/DictionaryDecoderImpl+UnboxDecodable.swift
Sources/DictionaryCoding/ISO8601DateFormatter+Shared.swift (can be deleted)
Summary
DictionaryEncoderandDictionaryDecoderare currentlyopen class. They should be converted topublic structand madeSendable.Proposed Changes
struct + Sendable
open class DictionaryEncoder→public struct DictionaryEncoder: Sendableopen class DictionaryDecoder→public struct DictionaryDecoder: Sendableopen varproperties →public varuserInfo
userInfo: [CodingUserInfoKey: Any]→userInfo: [CodingUserInfoKey: any Sendable]on both typesDictionaryEncoderOptionsandDictionaryDecoderOptionsto match[CodingUserInfoKey: any Sendable]→[CodingUserInfoKey: Any]inDictionaryEncoderImpl/DictionaryDecoderImplto satisfy theEncoder/Decoderprotocol requirementRemove DateEncodingStrategy / DateDecodingStrategy
Unlike JSON,
[String: Any]can hold aDatevalue natively — no serialization to string or number is needed. The strategies.secondsSince1970,.millisecondsSince1970,.iso8601, and.formatted(DateFormatter)only make sense for formats that cannot representDatedirectly. For a dictionary,.deferredToDateis the only meaningful strategy, so the entireDateEncodingStrategy/DateDecodingStrategyenums can be removed. This also eliminates theDateFormatter/Sendableproblem entirely and allows the struct to conform toSendablewithout@unchecked.Other Sendable fixes
MissingValueDecodingStrategy.useDefault(defaults: [String: Any])→[String: any Sendable]@Sendableto all closure-typed enum cases (DataEncodingStrategy.custom,KeyEncodingStrategy.custom,DataDecodingStrategy.custom,KeyDecodingStrategy.custom)Files to Update
Sources/DictionaryCoding/DictionaryEncoder.swiftSources/DictionaryCoding/DictionaryDecoder.swiftSources/DictionaryCoding/DictionaryEncoderOptions.swiftSources/DictionaryCoding/DictionaryDecoderOptions.swiftSources/DictionaryCoding/DictionaryEncoderImpl.swiftSources/DictionaryCoding/DictionaryDecoderImpl.swiftSources/DictionaryCoding/DictionaryEncoderImpl+Box.swiftSources/DictionaryCoding/DictionaryDecoderImpl+UnboxDecodable.swiftSources/DictionaryCoding/ISO8601DateFormatter+Shared.swift(can be deleted)