Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Last active July 1, 2020 12:51
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 anupamchugh/d337f547f1b2a9987a642b7a31d54bb8 to your computer and use it in GitHub Desktop.
Save anupamchugh/d337f547f1b2a9987a642b7a31d54bb8 to your computer and use it in GitHub Desktop.
struct ChuckJokes : Decodable {
let type : String?
let value : [ChuckValue]?
enum CodingKeys: String, CodingKey {
case type = "type"
case value = "value"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
type = try values.decodeIfPresent(String.self, forKey: .type)
value = try values.decodeIfPresent([ChuckValue].self, forKey: .value)
}
}
struct ChuckValue : Decodable {
let id : Int?
let joke : String?
enum CodingKeys: String, CodingKey {
case id = "id"
case joke = "joke"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
id = try values.decodeIfPresent(Int.self, forKey: .id)
joke = try values.decodeIfPresent(String.self, forKey: .joke)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment