Swift 4\'s new Encodable
/Decodable
protocols make JSON (de)serialization quite pleasant. However, I have not yet found a way to have fine-grained c
While this can be done it ultimately ends up being very unSwifty and even unJSONy. I think I see where you are coming from, the concept of #id
s is prevalent in HTML, but it is rarely transported over to the world of JSON
which I consider a good thing (TM).
Some Codable
structs will be able to parse your JSON
file just fine if you restructure it using recursive hashes, i.e. if your recipe
just contains an array of ingredients
which in turn contains (one or several) ingredient_info
. That way the parser will help you to stitch your network together in the first place and you only have to provide some backlinks through a simple traversal the structure if you really need them. Since this requires a thorough rework of your JSON
and your data structure I only sketch out the idea for you to think about it. If you deem it acceptable please tell me in the comments then I could elaborate it further, but depending on the circumstances you may not be at the liberty to change either one of them.