-
-
Save anupamchugh/d337f547f1b2a9987a642b7a31d54bb8 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
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