-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repository.swift
37 lines (30 loc) · 1.02 KB
/
Repository.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// Repository.swift
// GitHubSearchRepository
//
// Created by TodaChihaya on 2017/06/28.
// Copyright © 2017年 TodaChihaya. All rights reserved.
//
import Foundation
struct Repository: JSONDecodable {
let id: Int
let name: String
let owner: User
init(json: Any) throws {
guard let dictionary = json as? [String: Any] else {
throw JSONDecodeError.invalidFormat(json: json)
}
guard let id = dictionary["id"] as? Int else {
throw JSONDecodeError.missingValue(key: "id", actualValue: dictionary["id"])
}
guard let name = dictionary["name"] as? String else {
throw JSONDecodeError.missingValue(key: "name", actualValue: dictionary["name"])
}
guard let owner = dictionary["owner"] else {
throw JSONDecodeError.missingValue(key: "owner", actualValue: dictionary["owner"])
}
self.id = id
self.name = name
self.owner = try User(json: owner)
}
}