-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dog.swift
38 lines (27 loc) · 881 Bytes
/
Dog.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
//
// Dog.swift
// Codable
//
// Created by Nate Walczak on 10/2/18.
// Copyright © 2018 Detroit Labs. All rights reserved.
//
import Foundation
class Dog: Animal {
var numberOfBones: Int?
override init() {
super.init()
}
enum CodingKeys: CodingKey {
case numberOfBones
}
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.numberOfBones = try container.decodeIfPresent(Int.self, forKey: .numberOfBones)
try super.init(from: decoder)
}
override func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(numberOfBones, forKey: .numberOfBones)
try super.encode(to: encoder)
}
}