|
Hi all! ๐ It's my first post here, I'm a Python developer trying to learn Swift and already having issues ๐ I'm trying to decode "dependent" JSON API responses: let's imagine a fictional API with two endpoints:
I model each type with a Swift struct:
I want to decode the response from
I also tried another custom initializer with an extra parameter but didn't find how I could call it:
To summarize, the API response from
One thing to keep in mind is that the code making the API calls and instantiating my Example code, including dummy API responses, can be found here. Sorry for the long post and thanks in advance for any help ๐ |
|
Hi! What about not mapping players to game during decoding JSON but later when you need it? You could (if it fits your app) create Players |
|
@nemecek-filip Thanks for your answer! If I understand you correctly, that would mean making the I'm just afraid that choosing this solution will be cumbersome because of all the |
|
I meant more like keeping |
|
I see, that makes sense! Meanwhile, I got another answer on StackOverflow and it looks more "Swifty" to me. The idea is to extend If you're interested in the full implementation details, please check the accepted answer on my StackOverflow question ๐ |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills โ itโs the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.