Last active
August 29, 2015 14:24
-
-
Save cwagdev/a7b1d38f80612f21dcd4 to your computer and use it in GitHub Desktop.
Revisions
-
cwagdev renamed this gist
Jul 14, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cwagdev created this gist
Jul 14, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ protocol ValueForKeyLookupable { func valueForKey(key: String) -> Any? } extension ValueForKeyLookupable { func valueForKey(key: String) -> Any? { let mirror = reflect(self) for index in 0..<mirror.count { let child = mirror[index] if key == child.0 {return child.1.value} } return nil } } struct Pt: ValueForKeyLookupable { let x: Int let y: Int init(_ x: Int, _ y: Int) {self.x = x; self.y = y} init(){self.init(0, 0)} } let p = Pt(2, 3) p.valueForKey("x") p.valueForKey("y")