Skip to content

simple inheritance #112

Closed Answered by soumyamahunt
robaho asked this question in Q&A
Oct 24, 2024 · 1 comments · 1 reply

You must be logged in to vote

I got dynamic coding with a protocol working but I'd rather not use that. It seems it only works with protocols and enums?

@robaho I am assuming you are talking about MetaProtocolCodable, you can use enums without having to use the MetaProtocolCodable. MetaCodable by itself provides untagged, external, internal and adjacent tagging enum decoding functionality. For your use case, it could look something like:

@Codable
struct Container
  let elements: [AOrB]

  @Codable
  @UnTagged
  enum AOrB {
    case b(name: String, location : String)
    case a(name: String)
  }
}

Please use discussion to ask these kind of queries. And use the proper templates when creating issues.

Replies: 1 comment 1 reply

You must be logged in to vote
1 reply
@robaho

Answer selected by soumyamahunt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #111 on October 25, 2024 05:12.