Skip to content

Instantly share code, notes, and snippets.

@lmumar
Forked from peeblesjs/gist:9288f79322ed3119ece4
Created July 14, 2014 23:18
Show Gist options
  • Save lmumar/08ea3b7593d6a6ee0d63 to your computer and use it in GitHub Desktop.
Save lmumar/08ea3b7593d6a6ee0d63 to your computer and use it in GitHub Desktop.
operator infix --> {}
func --> (instance: Any, key: String) -> Any? {
let mirror = reflect(instance)
for index in 0 ..< mirror.count {
let (childKey, childMirror) = mirror[index]
if childKey == key {
return childMirror.value
}
}
return nil
}
//Example
struct MyPoint {
let x: Float
let y: Float
}
let point = MyPoint(x: 1, y: 2)
point --> "x"
point --> "y"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment