Skip to content

Releases: swhitty/KeyValueCoder

0.8.0 snake_case

01 Jul 02:37
cc58455
Compare
Choose a tag to compare

What's Changed

  • snake_case keys via Encoding/Decoding strategies by @swhitty in #12

Full Changelog: 0.7.0...0.8.0

0.7.0 Sendable structs

17 Apr 22:45
Compare
Choose a tag to compare

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

19 Aug 02:18
96cadf3
Compare
Choose a tag to compare

Swift 6 language mode when available

IntDecodingStrategy

27 Jun 23:37
b542a92
Compare
Choose a tag to compare

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

08 Mar 22:05
241d0ea
Compare
Choose a tag to compare

Enables .enableExperimentalFeature("StrictConcurrency") and fixes warnings for Swift 5.10

Support WebAssembly (SwiftWASM)

24 Aug 13:22
1c7a9ff
Compare
Choose a tag to compare
  • Native UserDefaults types are decoded using existing getters.
  • UserDefaults and PropertyListDecoder/Encoder are conditionally removed when compiling for os(WASI)

Fix UserDefaults Date Encoding

28 Jul 06:34
49d8ad3
Compare
Choose a tag to compare

Adds a fix when encoding a single Date to UserDefaults would encode as a Double when it should be encoded as Date.

Initial Release

24 Jul 07:45
090df4e
Compare
Choose a tag to compare
0.1.0

NilEncodingStrategy