Newer
Older
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
39
import Foundation
public struct Fact: Equatable {
public init(
fact: String,
type: Int
) {
self.fact = fact
self.type = type
}
public var fact: String
public var type: Int
}
extension Fact: Codable {
enum CodingKeys: String, CodingKey {
case fact = "Fact"
case type = "Type"
}
static func decode(_ data: Data) throws -> Fact {
try JSONDecoder().decode(Self.self, from: data)
}
func encode() throws -> Data {
try JSONEncoder().encode(self)
}
}
extension Array where Element == Fact {
static func decode(_ data: Data) throws -> [Fact] {
try JSONDecoder().decode(Self.self, from: data)
}
func encode() throws -> Data {
try JSONEncoder().encode(self)
}
}