Created
April 8, 2019 02:40
-
-
Save juliantejera/b44dc9f92df7d9a9f0ee9c2018ca1d88 to your computer and use it in GitHub Desktop.
Alien with Decodable Container
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
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