@@ -35,7 +35,20 @@ class ReferencePerson : Equatable {
35
35
}
36
36
}
37
37
38
- class SubclassedPerson : ReferencePerson { }
38
+ class SubclassedPerson : ReferencePerson {
39
+ var hobby : String
40
+
41
+ required init ( ) {
42
+ self . hobby = " "
43
+ super. init ( )
44
+ }
45
+
46
+ init ( firstName: String , lastName: String , age: Int , hobby: String ) {
47
+ self . hobby = hobby
48
+ super. init ( firstName: firstName, lastName: lastName, age: age)
49
+ }
50
+
51
+ }
39
52
40
53
func == ( lhs: ReferencePerson , rhs: ReferencePerson ) -> Bool {
41
54
return lhs. firstName == rhs. firstName && lhs. lastName == rhs. lastName && lhs. age == rhs. age
@@ -116,6 +129,22 @@ public class PublicTests : XCTestCase {
116
129
XCTAssert ( person. lastName == lastName)
117
130
XCTAssert ( person. age == age)
118
131
}
132
+
133
+ func testPropertiesForSubclass( ) throws {
134
+ var props : [ Property ] = [ ]
135
+ let person = SubclassedPerson ( firstName: " Brad " , lastName: " Hilton " , age: 27 , hobby: " Golf " )
136
+ props = try properties ( person)
137
+ guard props. count == 4 else {
138
+ return XCTFail ( " Unexpected number of properties " )
139
+ }
140
+ guard let firstName = props [ 0 ] . value as? String , let lastName = props [ 1 ] . value as? String , let age = props [ 2 ] . value as? Int , let hobby = props [ 3 ] . value as? String else {
141
+ return XCTFail ( " Unexpected properties " )
142
+ }
143
+ XCTAssert ( person. firstName == firstName)
144
+ XCTAssert ( person. lastName == lastName)
145
+ XCTAssert ( person. age == age)
146
+ XCTAssert ( person. hobby == hobby)
147
+ }
119
148
120
149
func testSetValueForKeyOfInstance( ) throws {
121
150
var person = Person ( firstName: " Brad " , lastName: " Hilton " , age: 27 )
0 commit comments