forked from matthewcheok/JSONCodable
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassInheritance.swift
More file actions
58 lines (49 loc) · 1.38 KB
/
ClassInheritance.swift
File metadata and controls
58 lines (49 loc) · 1.38 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
//
// ClassInheritance.swift
// JSONCodable
//
// Created by Andy Steinmann on 7/14/16.
//
//
import Foundation
import JSONCodable
class Parent : JSONCodable
{
var parentProperty1:String = "parent1"
var parentProperty2:String = "parent2"
init(){
}
required init(object map: JSONObject) throws {
let decoder = JSONDecoder(object: map)
parentProperty1 = try decoder.decode("parentProperty1")
parentProperty2 = try decoder.decode("parentProperty2")
}
}
class Child : Parent
{
var childProperty1:String = "child1"
var childProperty2:String = "child2"
override init(){
super.init()
}
required init(object map: JSONObject) throws {
let decoder = JSONDecoder(object: map)
childProperty1 = try decoder.decode("childProperty1")
childProperty2 = try decoder.decode("childProperty2")
try super.init(object: map)
}
}
class Grandchild : Child
{
var grandChildProperty1:String = "grandChild1"
var grandChildProperty2:String = "grandChild2"
override init(){
super.init()
}
required init(object map: JSONObject) throws {
let decoder = JSONDecoder(object: map)
grandChildProperty1 = try decoder.decode("grandChildProperty1")
grandChildProperty2 = try decoder.decode("grandChildProperty2")
try super.init(object: map)
}
}