I have a struct Message
in Swift, which has a property data
.
struct Message {
let id: Int
let data: Data
}
I want to decode the struct Message
from JSON, where it's data
property's underlying type cannot be determined. An example JSON would be like:
{
"id": 3,
"data": {
"name": "Bob",
"age": 32
}
}
or:
{
"id": 3,
"data": {
"location": "New York",
"data": "2022-3-1"
}
}
Therefore, I'd like to store the data
as type Data
, and defer the actual decoding of data
to later time. Now, I just want to store the raw data. How should I achieve that in Swift? Thanks for helping.