I'm using Argo in a Swift app to decode JSON into objects. I have JSON like this:
"activities": [
{
"id": "intro-to-the-program",
"type": "session",
"audio": "intro-to-the-program.mp3"
},
{
"id": "goal-setting",
"type": "session",
"audio": "goal-setting.mp3"
},
{
"id": "onboarding-quiz",
"type": "quiz"
}
]
Based on the 'type', I actually want to instantiate a subclass of the Activity class (ActivitySession, ActivityQuiz etc) and have the subclass do its own decoding.
How can I do this? The top-level decode() function expects a return type of Decoded<Activity>
, and none of my approaches so far seem able to defeat it.