gonzalezreal / IndeterminateTypesWithCodable

Indeterminate Types with Codable in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Indeterminate Types with Codable in Swift

License:MIT License


Languages

Language:Swift 100.0%