-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModel.swift
35 lines (29 loc) · 1008 Bytes
/
Model.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
//
// Model.swift
// Noze.io / mod_swift / MacroExpress
//
// Created by Helge Heß on 6/3/16.
// Copyright © 2016-2021 ZeeZide GmbH. All rights reserved.
//
struct Todo: Encodable {
// Note: Decodable doesn't work for partial objects and has little to no
// value for the Todo-Backend API.
var id : Int
var title : String
var completed : Bool
var order : Int
var url : String { return "\(ourAPI)todos/\(id)" }
// Codable is a train wreck. We need all this boilerplate just to emit the
// extra `url`.
enum CodingKeys: String, CodingKey {
case id, title, completed, order, url
}
func encode(to encoder: Encoder) throws {
var values = encoder.container(keyedBy: CodingKeys.self)
try values.encode(url, forKey: .url)
try values.encode(id, forKey: .id)
try values.encode(title, forKey: .title)
try values.encode(completed, forKey: .completed)
try values.encode(order, forKey: .order)
}
}