Created
August 30, 2019 15:31
-
-
Save agiletalk/88a3f7742ec9f7331084134733a56d8c 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 Repo { | |
let name: String | |
let owner: User | |
let isPrivate: Bool | |
let license: String | |
enum CodingKeys: String, CodingKey { | |
case name | |
case owner | |
case isPrivate = "private" | |
case license | |
} | |
enum LicenseKeys: String, CodingKey { | |
case key | |
case name | |
case url | |
} | |
} | |
extension Repo: Decodable { | |
init(from decoder: Decoder) throws { | |
let values = try decoder.container(keyedBy: CodingKeys.self) | |
name = try values.decode(String.self, forKey: .name) | |
owner = try values.decode(User.self, forKey: .owner) | |
isPrivate = try values.decode(Bool.self, forKey: .isPrivate) | |
let licenseInfo = try values.nestedContainer(keyedBy: LicenseKeys.self) | |
license = try licenseInfo.decode(String.self, forKey: .name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment