CoreOffice / XMLCoder

Easy XML parsing using Codable protocols in Swift
https://coreoffice.github.io/XMLCoder/
MIT License
800 stars 112 forks source link

Replace value intrinsic with empty string key #149

Closed bwetherfield closed 4 years ago

bwetherfield commented 5 years ago

Overview

Restricts the special case usage of "value" OR "" as a coding key, as implemented in #73 to just "". "value" resumes functioning as a normal coding key.

Example

As noted in #145, "value" is starting to collide awkwardly in one or two cases where it may be implicit per the special case usage

<value-containing>I am implicitly labeled</value-containing>

or explicit, as in

<value-containing>
    <value>I am explicitly labeled</value>
</value-containing>

With the change proposed, the latter example will be unambiguously captured by

struct ValueContaining: Codable {
    let value: String
}

while the former is equivalent to

struct ValueContaining: Codable {
    let value: String

    enum CodingKeys: String, CodingKey {
        case value = ""
    }
}

Source Compatability

This is a breaking change for downstream users of the special "value" coding key. All such uses should be replaced by case value = "" subject to this PR's inclusion.

bwetherfield commented 5 years ago

If this change goes through, and anyone, like us, find that a bunch of explicit CodingKey implementations are now needed (where before you just set-and-forgot a variable let value: String, for example), you may find this template helpful (for use with Sourcery).

MaxDesiatov commented 4 years ago

@bwetherfield thanks for the PR!