Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Created June 22, 2014 07:04
Show Gist options
  • Save jspahrsummers/2f482aa03009cb7a8646 to your computer and use it in GitHub Desktop.
Save jspahrsummers/2f482aa03009cb7a8646 to your computer and use it in GitHub Desktop.
Capturing an `inout` parameter for later use
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