Releases: swhitty/KeyValueCoder
0.8.0 snake_case
What's Changed
Full Changelog: 0.7.0...0.8.0
0.7.0 Sendable structs
Convert the top level types KeyValueEncoder
and KeyValueDecoder
from class
to struct
so they can easily become Sendable
without adding a lock. #11
UserInfo now requires any Sendable
values preventing any non sendable values from crossing currency domains:
var userInfo: [CodingUserInfoKey: any Sendable]
While these are API breaking changes the fixit is easy to convert let decoder
to var decoder
where required. Fixing the userInfo is possible with an @unchecked Sendable
box, but this API is rarely used anyway.
Swift 6
IntDecodingStrategy
The decoding of BinaryInteger
types (Int
, UInt
etc) can now be adjusted via intDecodingStrategy
.
The default strategy IntDecodingStrategy.exact
is the previous behaviour and ensures the source value is exactly represented by the decoded type allowing floating point values with no fractional part to be decoded:
// [10, 20, -30, 50]
let values = try KeyValueDecoder().decode([Int8].self, from: [10, 20.0, -30.0, Int64(50)])
// throws DecodingError.typeMismatch because 1000 cannot be exactly represented by Int8
_ = try KeyValueDecoder().decode(Int8.self, from: 1000])
Values with a fractional part can also be decoded to integers by rounding with any FloatingPointRoundingRule
:
let decoder = KeyValueDecoder()
decoder.intDecodingStrategy = .rounding(rule: .toNearestOrAwayFromZero)
// [10, -21, 50]
let values = try decoder.decode([Int].self, from: [10.1, -20.9, 50.00001]),
Values can also be clamped to the representable range:
let decoder = KeyValueDecoder()
decoder.intDecodingStrategy = .clamping(roundingRule: .toNearestOrAwayFromZero)
// [10, 21, 127, -128]
let values = try decoder.decode([Int8].self, from: [10, 20.5, 1000, -Double.infinity])
Many thanks to @eun-ice for the suggestion.
Swift 5.10
Enables .enableExperimentalFeature("StrictConcurrency")
and fixes warnings for Swift 5.10
Support WebAssembly (SwiftWASM)
- Native
UserDefaults
types are decoded using existing getters. UserDefaults
andPropertyListDecoder/Encoder
are conditionally removed when compiling for os(WASI)
Fix UserDefaults Date Encoding
Adds a fix when encoding a single Date
to UserDefaults
would encode as a Double
when it should be encoded as Date
.
Initial Release
0.1.0 NilEncodingStrategy