-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gist.swift
38 lines (30 loc) · 1.05 KB
/
Gist.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
38
//
// Gist.swift
// RESThub
//
// Created by Harrison on 7/30/19.
// Copyright © 2019 Harrison. All rights reserved.
//
import Foundation
struct Gist: Encodable {
var id: String?
var isPublic: Bool
var description: String
enum CodingKeys: String, CodingKey {
case id, description, isPublic = "public"
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(isPublic, forKey: .isPublic)
try container.encode(description, forKey: .description)
try container.encodeIfPresent(id, forKey: .id)
}
}
extension Gist: Decodable {
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.isPublic = try container.decode(Bool.self, forKey: .isPublic)
self.description = try container.decodeIfPresent(String.self, forKey: .description) ?? "Description is nil"
}
}