Skip to content

Instantly share code, notes, and snippets.

@emma-k-alexandra
Created July 18, 2020 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emma-k-alexandra/234a7385908212670579ff0325e37889 to your computer and use it in GitHub Desktop.
Save emma-k-alexandra/234a7385908212670579ff0325e37889 to your computer and use it in GitHub Desktop.
init(from decoder: Decoder) throws {
let baseContainer = try decoder.container(keyedBy: BaseContent.CodingKeys.self)
let type = try baseContainer.decode(BaseContent.ContentType.self, forKey: .type)
let container = try decoder.singleValueContainer()
switch type {
case .header:
self = .header(try container.decode(Header.self))
case .paragraph:
self = .paragraph(try container.decode(Paragraph.self))
case .footer:
self = .footer(try container.decode(Footer.self))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment