Replies: 1 comment
-
The default behaviour for MetaCodable with enums is to look for identifier distinguishing the case. You can opt out of any identifiers by using UnTagged macro
You can opt out of keyed decoding of some fields for structs as well by passing no arguments to CodedAt macro for that field. Here is a sample example. |
Beta Was this translation helpful? Give feedback.
-
I have a REST response that comes in one of two format, wanting me to have an enum like this:
The corresponding JSON for the first case corresponds to a [[String: T]] (and I have been able to create a HelperCode to transform that to [T]. The second case looks like a dictionary where one of the keys (different names for different T.type) has to above list value, and there may be several other keys that I would want to decode into the PaginationInfo (it has some optional values).
The problem I am having is that currently, when using @codable on the enum, it wants to look for key names "list" and "paginated." How do you use MetaCodable to do this as described?
An alternative, if the above is not possible, is to use:
but, due to the formats returned, all item lists will have a different key (in other words looking for "items") will not work. I know I can also not use MetaCodable and write a completely custom init(from:).
Beta Was this translation helpful? Give feedback.
All reactions