Closed Aquilosion closed 6 years ago
The design here was intentional. We intended for outside dependencies/modifications to be made through var
and optional properties. I recognize this is not ideal, but it was a conscious choice made for complexity.
While it's useful when I can use it, I often find that I cannot use
JSONDecodable
because either:JSON
object, or;JSON
to it.This poses a problem if I want to pass a partial
JSON
to an object. For example, if I have the following JSON:And the following struct which takes in the contents:
It appears to be impossible to initialise a
TestObject
with the contents of thetest_object
key without using some verbose code. Ideally, I would do something like this to create my instance, after loading the entire JSON above:This hypothetical
value
method would probably look something like the below in JSONSubscripting.swift, but I can find no such method:Unfortunately I can't even extend
JSON
to provide this method myself, asvalueAtPath
is private. Instead, the closest things I can find to achieve the desired behaviour:Is there something I'm missing, or is there something wrong with my general approach? Or, could Freddy benefit from a throwing
value
method?