-
-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathStatusEdit.swift
More file actions
234 lines (208 loc) · 6.92 KB
/
StatusEdit.swift
File metadata and controls
234 lines (208 loc) · 6.92 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
import Foundation
import CoreData
public final class StatusEdit: NSManagedObject {
public final class Poll: NSObject, Codable {
public final class Option: NSObject, Codable {
public let title: String
public init(title: String) {
self.title = title
}
}
public let options: [Option]
public init(options: [Option]) {
self.options = options
}
}
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public var createdAt: Date
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public var content: String
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public var sensitive: Bool
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public var spoilerText: String?
// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public var status: Status?
// MARK: - AutoGenerateProperty
// sourcery:inline:StatusEdit.AutoGenerateProperty
// Generated using Sourcery
// DO NOT EDIT
public struct Property {
public let createdAt: Date
public let content: String
public let sensitive: Bool
public let spoilerText: String?
public let emojis: [MastodonEmoji]
public let attachments: [MastodonAttachment]
public let poll: Poll?
public init(
createdAt: Date,
content: String,
sensitive: Bool,
spoilerText: String?,
emojis: [MastodonEmoji],
attachments: [MastodonAttachment],
poll: Poll?
) {
self.createdAt = createdAt
self.content = content
self.sensitive = sensitive
self.spoilerText = spoilerText
self.emojis = emojis
self.attachments = attachments
self.poll = poll
}
}
public func configure(property: Property) {
self.createdAt = property.createdAt
self.content = property.content
self.sensitive = property.sensitive
self.spoilerText = property.spoilerText
self.emojis = property.emojis
self.attachments = property.attachments
self.poll = property.poll
}
public func update(property: Property) {
update(createdAt: property.createdAt)
update(content: property.content)
update(sensitive: property.sensitive)
update(spoilerText: property.spoilerText)
update(emojis: property.emojis)
update(attachments: property.attachments)
update(poll: property.poll)
}
// sourcery:end
// sourcery: autoUpdatableObject, autoGenerateProperty
@objc public var emojis: [MastodonEmoji] {
get {
let keyPath = #keyPath(StatusEdit.emojis)
willAccessValue(forKey: keyPath)
let _data = primitiveValue(forKey: keyPath) as? Data
didAccessValue(forKey: keyPath)
do {
guard let data = _data else { return [] }
let emojis = try JSONDecoder().decode([MastodonEmoji].self, from: data)
return emojis
} catch {
assertionFailure(error.localizedDescription)
return []
}
}
set {
let keyPath = #keyPath(StatusEdit.emojis)
let data = try? JSONEncoder().encode(newValue)
willChangeValue(forKey: keyPath)
setPrimitiveValue(data, forKey: keyPath)
didChangeValue(forKey: keyPath)
}
}
}
extension StatusEdit {
// sourcery: autoUpdatableObject, autoGenerateProperty
@objc public var attachments: [MastodonAttachment] {
get {
let keyPath = #keyPath(StatusEdit.attachments)
willAccessValue(forKey: keyPath)
let _data = primitiveValue(forKey: keyPath) as? Data
didAccessValue(forKey: keyPath)
do {
guard let data = _data else { return [] }
let attachments = try JSONDecoder().decode([MastodonAttachment].self, from: data)
return attachments
} catch {
assertionFailure(error.localizedDescription)
return []
}
}
set {
let keyPath = #keyPath(StatusEdit.attachments)
let data = try? JSONEncoder().encode(newValue)
willChangeValue(forKey: keyPath)
setPrimitiveValue(data, forKey: keyPath)
didChangeValue(forKey: keyPath)
}
}
}
extension StatusEdit {
// sourcery: autoUpdatableObject, autoGenerateProperty
@objc public var poll: Poll? {
get {
let keyPath = #keyPath(StatusEdit.poll)
willAccessValue(forKey: keyPath)
let _data = primitiveValue(forKey: keyPath) as? Data
didAccessValue(forKey: keyPath)
do {
guard let data = _data else { return nil }
let poll = try JSONDecoder().decode(Poll.self, from: data)
return poll
} catch {
return nil
}
}
set {
let keyPath = #keyPath(StatusEdit.poll)
let data = try? JSONEncoder().encode(newValue)
willChangeValue(forKey: keyPath)
setPrimitiveValue(data, forKey: keyPath)
didChangeValue(forKey: keyPath)
}
}
}
extension StatusEdit: Managed {
@discardableResult
public static func insert(
into context: NSManagedObjectContext,
property: Property
) -> StatusEdit {
let object: StatusEdit = context.insertObject()
object.configure(property: property)
return object
}
}
extension StatusEdit: AutoUpdatableObject {
// sourcery:inline:StatusEdit.AutoUpdatableObject
// Generated using Sourcery
// DO NOT EDIT
public func update(createdAt: Date) {
if self.createdAt != createdAt {
self.createdAt = createdAt
}
}
public func update(content: String) {
if self.content != content {
self.content = content
}
}
public func update(sensitive: Bool) {
if self.sensitive != sensitive {
self.sensitive = sensitive
}
}
public func update(spoilerText: String?) {
if self.spoilerText != spoilerText {
self.spoilerText = spoilerText
}
}
public func update(status: Status?) {
if self.status != status {
self.status = status
}
}
public func update(emojis: [MastodonEmoji]) {
if self.emojis != emojis {
self.emojis = emojis
}
}
public func update(attachments: [MastodonAttachment]) {
if self.attachments != attachments {
self.attachments = attachments
}
}
public func update(poll: Poll?) {
if self.poll != poll {
self.poll = poll
}
}
// sourcery:end
}