IndeterminateTypesWithCodable
IndeterminateTypesWithCodable copied to clipboard
Indeterminate Types with Codable in Swift
Indeterminate Types with Codable in Swift
This playground explores two different approaches to decode or encode JSON containing objects whose type is determined by a property.
{
"from": "Guille",
"text": "Look what I just found!",
"attachments": [
{
"type": "image",
"payload": {
"url": "http://via.placeholder.com/640x480",
"width": 640,
"height": 480
}
},
{
"type": "audio",
"payload": {
"title": "Never Gonna Give You Up",
"url": "https://audio.com/NeverGonnaGiveYouUp.mp3",
"shouldAutoplay": true,
}
}
]
}
You can find the full blog post here.