Skip to content

Instantly share code, notes, and snippets.

@agiletalk
Created August 30, 2019 15:31
Show Gist options
  • Save agiletalk/88a3f7742ec9f7331084134733a56d8c to your computer and use it in GitHub Desktop.
Save agiletalk/88a3f7742ec9f7331084134733a56d8c to your computer and use it in GitHub Desktop.
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