Created
July 18, 2020 01:55
-
-
Save emma-k-alexandra/234a7385908212670579ff0325e37889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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