-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.swift
More file actions
32 lines (26 loc) · 900 Bytes
/
User.swift
File metadata and controls
32 lines (26 loc) · 900 Bytes
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
//
// User.swift
// GitHubSearchRepository
//
// Created by 岡田直道 on 2017/07/12.
// Copyright © 2017年 Naomichi Okada. All rights reserved.
//
import Foundation
struct User : JSONDecodable {
let id: Int
let login: String
// Any型から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 login = dictionary["login"] as? String else {
throw JSONDecodeError.missingValue(key: "login", actualValue: dictionary["login"])
}
self.id = id
self.login = login
}
}