Releases: swhitty/KeyValueCoder
Releases · swhitty/KeyValueCoder
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