-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAnotherFamily.swift
37 lines (29 loc) · 1007 Bytes
/
AnotherFamily.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
//
// AnotherFamily.swift
// Codable
//
// Created by Nate Walczak on 3/20/20.
// Copyright © 2020 Detroit Labs. All rights reserved.
//
import Foundation
class AnotherFamily: Codable {
var mother: Contact?
var father: Contact?
var brother: Contact?
var sister: Contact?
init() {
}
enum CodingKeys: CodingKey {
case mother
case father
case brother
case sister
}
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.mother = try container.decodeIfPresent(NilOnEmpty<Contact>.self, forKey: .mother)?.value
self.father = try container.decodeIfPresent(NilOnEmpty<Contact>.self, forKey: .father)?.value
self.brother = try container.decodeIfPresent(NilOnEmpty<Contact>.self, forKey: .brother)?.value
self.sister = try container.decodeIfPresent(NilOnEmpty<Contact>.self, forKey: .sister)?.value
}
}