File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -213,3 +213,23 @@ extension DateInterval : _ObjectiveCBridgeable {
213
213
return result!
214
214
}
215
215
}
216
+
217
+ extension DateInterval : Codable {
218
+ enum CodingKeys : String , CodingKey {
219
+ case start
220
+ case duration
221
+ }
222
+
223
+ public init ( from decoder: Decoder ) throws {
224
+ let container = try decoder. container ( keyedBy: CodingKeys . self)
225
+ let start = try container. decode ( Date . self, forKey: . start)
226
+ let duration = try container. decode ( TimeInterval . self, forKey: . duration)
227
+ self . init ( start: start, duration: duration)
228
+ }
229
+
230
+ public func encode( to encoder: Encoder ) throws {
231
+ var container = encoder. container ( keyedBy: CodingKeys . self)
232
+ try container. encode ( self . start, forKey: . start)
233
+ try container. encode ( self . duration, forKey: . duration)
234
+ }
235
+ }
You can’t perform that action at this time.
0 commit comments