Open NSExceptional opened 3 years ago
The sample is
struct Book: Codable, Equatable, DynamicNodeEncoding { let id: UInt let title: String let categories: [Category] }
And yours are
let elements: [Element]
So in you code the category
should be [[String]], and the enum couldn't do that.
That's my opinion, I didn't test it with code. You should give it a try.
I'm not sure you understood my example, but I'm not sure how to make it more clear. I'm not sure how you interpreted it, I don't understand what you're trying to say.
That said, I would like to preserve type information, so I don't want everything to be String
I see. You are requesting a new feature instead of reporting a new issue. I thought you wanted to fixed your code. But you were not. In this way, I will quit this discussion as I think the liability is on your side.
That's a really interesting and harsh response. I didn't know I was asking for a feature request when I opened the issue.
I'll take that to mean "what you're asking for is not possible due to limitations of the Codable APIs," though, which would indeed make this a feature request if we assume that is the case, I guess.
For anyone else reading, I would like to clarify with a better example:
<body>
<p>hello</p>
<em>spicy</em>
<h1>taco</h1>
<p>goodbye</p>
<p>friends</p>
</body>
Assuming these tags won't contain other tags, is it possible to decode these, retaining order and type information? I don't know how to do this with this framework. @MaxDesiatov maybe you know the answer to this?
Lets take your book example:
If we switch it around like this, so that the order of elements no longer follows your set schema:
… we would have to decode it like so:
I don't see a way to possibly decode this by hand. If you iterate over the container's keys and try to decode them, you will get stuck at the first
category
(Kids) which will be decoded twice, and never decode the second one. Same for any other keys that are duplicated. I even tried making theCodingKeys
a class to give them some sort of inherent identity and that didn't work. Sample init:So far, I am not inclined to think this is the fault of this library. This seems more like a limitation of Codable to me, unless this is something you know how to address right away.