Created
June 22, 2014 07:04
-
-
Save jspahrsummers/2f482aa03009cb7a8646 to your computer and use it in GitHub Desktop.
Capturing an `inout` parameter for later use
This file contains 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 characters
struct Property<T> { | |
let name: String | |
let _getter: () -> T | |
let _setter: T -> () | |
var value: T { | |
get { | |
return _getter() | |
} | |
set(newValue) { | |
_setter(newValue) | |
} | |
} | |
init(name: String, inout value: T) { | |
self.name = name | |
_getter = { value } | |
_setter = { value = $0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment