Skip to content

Instantly share code, notes, and snippets.

@juliantejera
Created April 8, 2019 02:40
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 juliantejera/b44dc9f92df7d9a9f0ee9c2018ca1d88 to your computer and use it in GitHub Desktop.
Save juliantejera/b44dc9f92df7d9a9f0ee9c2018ca1d88 to your computer and use it in GitHub Desktop.
Alien with Decodable Container
struct Alien: Decodable {
private enum CodingKeys: String, CodingKey {
case humans
}
let humans: [Human]
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
humans = (try container.decode([DecodableContainer<Human>].self, forKey: .humans)).compactMap { $0.value }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment