Skip to content

Instantly share code, notes, and snippets.

// Enum with type as type of the content
// Assciated value will hold the actual content data
enum BodyContent {
case number(Int)
case text(String)
case unsupported
}
// Now we can represent our Models as
struct Content: Decodable {
struct Content: Decodable {
var body: [Body]
}
struct Body: Decodable {
var type: String
var content: ???
}
{
"body":[
{
"type":"string",
"content":"Lorem ipsum text"
},
{
"type":"int",
"content":10
}